-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat(settings): allow resizing the columns of the accounts list #62066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Fantu
wants to merge
2
commits into
nextcloud:master
Choose a base branch
from
M2Rbiz:feat/users-list-resizable-columns
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
apps/settings/src/components/Users/UserColumnResizer.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { mount } from '@vue/test-utils' | ||
| import { describe, expect, it } from 'vitest' | ||
| import UserColumnResizer from './UserColumnResizer.vue' | ||
| import { COLUMN_MIN_WIDTH, COLUMN_RESIZE_STEP } from '../../utils/userListColumns.ts' | ||
|
|
||
| const CELL_WIDTH = 300 | ||
|
|
||
| // jsdom has no PointerEvent and wrapper.trigger() cannot set the read-only | ||
| // clientX, so dispatch a MouseEvent carrying the pointer event type instead | ||
| function firePointerEvent(element: Element, type: string, clientX: number) { | ||
| element.dispatchEvent(new MouseEvent(type, { bubbles: true, clientX })) | ||
| } | ||
|
|
||
| function mountInHeaderCell() { | ||
| const wrapper = mount({ | ||
| components: { UserColumnResizer }, | ||
| template: ` | ||
| <table> | ||
| <tr> | ||
| <th> | ||
| <UserColumnResizer column="email" label="Email" /> | ||
| </th> | ||
| </tr> | ||
| </table> | ||
| `, | ||
| }) | ||
| wrapper.find('th').element.getBoundingClientRect = () => ({ width: CELL_WIDTH } as DOMRect) | ||
| return wrapper | ||
| } | ||
|
|
||
| describe('UserColumnResizer', () => { | ||
| it('widens the column with the right arrow key', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| await resizer.trigger('keydown', { key: 'ArrowRight' }) | ||
|
|
||
| expect(resizer.emitted('resize')).toEqual([[CELL_WIDTH + COLUMN_RESIZE_STEP]]) | ||
| expect(resizer.emitted('resize-end')).toHaveLength(1) | ||
| }) | ||
|
|
||
| it('narrows the column with the left arrow key', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| await resizer.trigger('keydown', { key: 'ArrowLeft' }) | ||
|
|
||
| expect(resizer.emitted('resize')).toEqual([[CELL_WIDTH - COLUMN_RESIZE_STEP]]) | ||
| }) | ||
|
|
||
| it('ignores unrelated keys', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| await resizer.trigger('keydown', { key: 'Enter' }) | ||
|
|
||
| expect(resizer.emitted('resize')).toBeUndefined() | ||
| }) | ||
|
|
||
| it('resizes on pointer drag and clamps to the minimum width', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| firePointerEvent(resizer.element, 'pointerdown', 500) | ||
| firePointerEvent(resizer.element, 'pointermove', 550) | ||
| firePointerEvent(resizer.element, 'pointermove', 100) | ||
| firePointerEvent(resizer.element, 'pointerup', 100) | ||
| await resizer.vm.$nextTick() | ||
|
|
||
| expect(resizer.emitted('resize')).toEqual([[CELL_WIDTH + 50], [COLUMN_MIN_WIDTH]]) | ||
| expect(resizer.emitted('resize-end')).toHaveLength(1) | ||
| }) | ||
|
|
||
| it('does not resize on pointer move without a preceding pointer down', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| firePointerEvent(resizer.element, 'pointermove', 550) | ||
| await resizer.vm.$nextTick() | ||
|
|
||
| expect(resizer.emitted('resize')).toBeUndefined() | ||
| }) | ||
|
|
||
| it('emits a reset on double click', async () => { | ||
| const wrapper = mountInHeaderCell() | ||
| const resizer = wrapper.findComponent(UserColumnResizer) | ||
|
|
||
| await resizer.trigger('dblclick') | ||
|
|
||
| expect(resizer.emitted('reset')).toHaveLength(1) | ||
| }) | ||
| }) |
128 changes: 128 additions & 0 deletions
128
apps/settings/src/components/Users/UserColumnResizer.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <span | ||
| class="column-resizer" | ||
| role="separator" | ||
| aria-orientation="vertical" | ||
| :aria-label="t('settings', 'Drag or use the arrow keys to resize the {label} column. Double click to reset its width.', { label })" | ||
| tabindex="0" | ||
| :data-cy-column-resizer="column" | ||
| @pointerdown.prevent="onPointerDown" | ||
| @pointermove="onPointerMove" | ||
| @pointerup="onPointerUp" | ||
| @pointercancel="onPointerUp" | ||
| @keydown="onKeydown" | ||
| @dblclick="$emit('reset')" /> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import { translate as t } from '@nextcloud/l10n' | ||
| import Vue from 'vue' | ||
| import { clampColumnWidth, COLUMN_RESIZE_STEP } from '../../utils/userListColumns.ts' | ||
|
|
||
| export default Vue.extend({ | ||
| name: 'UserColumnResizer', | ||
|
|
||
| props: { | ||
| /** Column key, used as CSS variable suffix */ | ||
| column: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
|
|
||
| /** Human readable column label */ | ||
| label: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| }, | ||
|
|
||
| data() { | ||
| return { | ||
| dragging: false, | ||
| startX: 0, | ||
| startWidth: 0, | ||
| } | ||
| }, | ||
|
|
||
| methods: { | ||
| t, | ||
|
|
||
| cellWidth(): number { | ||
| const cell = (this.$el as HTMLElement).closest('th') | ||
| return cell?.getBoundingClientRect().width ?? 0 | ||
| }, | ||
|
|
||
| resizeDirection(): number { | ||
| return document.dir === 'rtl' ? -1 : 1 | ||
| }, | ||
|
|
||
| onPointerDown(event: PointerEvent) { | ||
| this.dragging = true | ||
| this.startX = event.clientX | ||
| this.startWidth = this.cellWidth() | ||
| const handle = event.target as HTMLElement | ||
| handle.setPointerCapture?.(event.pointerId) | ||
| }, | ||
|
|
||
| onPointerMove(event: PointerEvent) { | ||
| if (!this.dragging) { | ||
| return | ||
| } | ||
| const delta = (event.clientX - this.startX) * this.resizeDirection() | ||
| this.$emit('resize', clampColumnWidth(this.startWidth + delta)) | ||
| }, | ||
|
|
||
| onPointerUp() { | ||
| if (!this.dragging) { | ||
| return | ||
| } | ||
| this.dragging = false | ||
| this.$emit('resize-end') | ||
| }, | ||
|
|
||
| onKeydown(event: KeyboardEvent) { | ||
| const direction = { ArrowLeft: -1, ArrowRight: 1 }[event.key] | ||
| if (direction === undefined) { | ||
| return | ||
| } | ||
| event.preventDefault() | ||
| const step = direction * COLUMN_RESIZE_STEP * this.resizeDirection() | ||
| this.$emit('resize', clampColumnWidth(this.cellWidth() + step)) | ||
| this.$emit('resize-end') | ||
| }, | ||
| }, | ||
| }) | ||
| </script> | ||
|
|
||
| <style lang="scss" scoped> | ||
| .column-resizer { | ||
| position: absolute; | ||
| z-index: 2; | ||
| inset-block: 0; | ||
| inset-inline-end: 0; | ||
| width: calc(var(--default-grid-baseline) * 2); | ||
| cursor: col-resize; | ||
| touch-action: none; | ||
|
|
||
| &::after { | ||
| content: ''; | ||
| position: absolute; | ||
| inset-block: var(--default-grid-baseline); | ||
| inset-inline-end: calc(var(--default-grid-baseline) / 2); | ||
| width: 2px; | ||
| border-radius: 1px; | ||
| background-color: var(--color-primary-element); | ||
| opacity: 0; | ||
| } | ||
|
|
||
| &:hover::after, | ||
| &:focus-visible::after { | ||
| opacity: 1; | ||
| } | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.