An open source design system that's fully customizable and agent ready
TypeScript
fix(TransferListSelector): a disabled selector keeps its row controls and search focusable (#10192)
Cindy Zhang1ab06796275c
diff --git a/packages/lab/src/TransferList/TransferList.doc.mjs b/packages/lab/src/TransferList/TransferList.doc.mjsindex b536351c9b..e5b099c6be 100644--- a/packages/lab/src/TransferList/TransferList.doc.mjs+++ b/packages/lab/src/TransferList/TransferList.doc.mjs@@ -325,6 +325,13 @@ export const docs = {'Shows a shared search field that filters both lists by label and description.',default: 'false',},+ {+ name: 'isDisabled',+ type: 'boolean',+ description:+ 'Disables every transfer, reorder, Clear, Add all and search control. The row controls and the search field stay focusable.',+ default: 'false',+ },{name: 'searchLabel',type: 'string',@@ -751,6 +758,8 @@ export const docsDense = {selectedLabel: 'Selected-list heading and name.',availableLabel: 'Available-list heading and name.',hasSearch: 'Shared list filter; default false.',+ isDisabled:+ 'Disable every control; rows and search stay focusable; default false.',searchLabel: 'Accessible search label.',searchPlaceholder: 'Search placeholder.',isReorderable: 'Enable pointer and keyboard ordering; default true.',diff --git a/packages/lab/src/TransferList/TransferList.test.tsx b/packages/lab/src/TransferList/TransferList.test.tsxindex af83934642..2bd40a6718 100644--- a/packages/lab/src/TransferList/TransferList.test.tsx+++ b/packages/lab/src/TransferList/TransferList.test.tsx@@ -131,6 +131,36 @@ afterEach(() => {});describe('TransferList', () => {+ it('disables every control while keeping them focusable, without option-specific messages', () => {+ const onChange = vi.fn();+ render(+ <TransferList+ label="Columns"+ options={LOCKED_OPTIONS}+ value={['name', 'owner']}+ onChange={onChange}+ hasSearch+ isDisabled+ />,+ );+ const remove = screen.getByRole('button', {name: 'Remove Name'});+ expect(remove).toHaveAttribute('aria-disabled', 'true');+ expect(remove).not.toHaveAttribute('disabled');+ remove.focus();+ expect(remove).toHaveFocus();+ fireEvent.click(remove);+ expect(onChange).not.toHaveBeenCalled();+ expect(+ screen.getByRole('button', {name: 'Remove Owner'}),+ ).not.toHaveAccessibleDescription(+ 'Owner is required and fixed in position.',+ );+ expect(screen.getByRole('searchbox')).toHaveAttribute(+ 'aria-disabled',+ 'true',+ );+ });+describe('semantics and content', () => {it('renders a labelled pair of semantic lists without listbox roles', () => {render(@@ -895,6 +925,33 @@ describe('TransferList', () => {expect(handle).toHaveFocus();});+ it('ends a grab without any change when the list becomes disabled mid-reorder', async () => {+ const user = userEvent.setup();+ const onValueChange = vi.fn();+ const {rerender} = render(+ <ControlledTransferList+ initialValue={['name', 'owner', 'status']}+ onValueChange={onValueChange}+ />,+ );++ const handle = screen.getByRole('button', {name: 'Reorder Owner'});+ handle.focus();+ await user.keyboard('{Enter}{ArrowDown}');+ expect(onValueChange).toHaveBeenCalledTimes(1);++ rerender(+ <ControlledTransferList+ initialValue={['name', 'owner', 'status']}+ onValueChange={onValueChange}+ isDisabled+ />,+ );+ expect(handle).toHaveAttribute('aria-pressed', 'false');+ await user.keyboard('{Escape}');+ expect(onValueChange).toHaveBeenCalledTimes(1);+ });+it('does not allow a value to cross a reorder-disabled value', async () => {const user = userEvent.setup();const onValueChange = vi.fn();diff --git a/packages/lab/src/TransferList/TransferList.tsx b/packages/lab/src/TransferList/TransferList.tsxindex 13021ba90d..49aafa88e0 100644--- a/packages/lab/src/TransferList/TransferList.tsx+++ b/packages/lab/src/TransferList/TransferList.tsx@@ -129,6 +129,11 @@ export interface TransferListProps<T extends string = string> extends Omit<description?: string;/** Complete option catalog. Option values must be unique. */options: readonly TransferListOption<T>[];+ /**+ * Disables every transfer, reorder, Clear, Add all and search control. The+ * row controls and the search field stay focusable. @default false+ */+ isDisabled?: boolean;/** Ordered selected values. This array is the single source of truth. */value: readonly T[];/** Called with the next ordered selection after a committed change. */@@ -389,7 +394,8 @@ export function TransferList<T extends string = string>({label,isLabelHidden = false,description,- options,+ options: optionsFromProps,+ isDisabled = false,value,onChange,selectedLabel: selectedLabelFromProps,@@ -460,6 +466,21 @@ export function TransferList<T extends string = string>({[],);+ // An option's own message names its own constraint.+ // It does not apply to a disabled list.+ const options = useMemo(+ () =>+ isDisabled+ ? optionsFromProps.map(option => ({+ ...option,+ isTransferDisabled: true,+ isReorderDisabled: true,+ disabledMessage: undefined,+ }))+ : optionsFromProps,+ [isDisabled, optionsFromProps],+ );+const optionByValue = useMemo(() => {const map = new Map<T, TransferListOption<T>>();options.forEach(option => map.set(option.value, option));@@ -748,6 +769,12 @@ export function TransferList<T extends string = string>({if (!session) {return;}+ // A list disabled mid-reorder takes no change from it, not even the+ // cancel that restores the order from before the grab.+ if (isDisabled) {+ setReorderSession(null);+ return;+ }if (session.mode === 'pointer') {if (cancelled || !session.hasPointerMoved) {setReorderSession(null);@@ -805,7 +832,7 @@ export function TransferList<T extends string = string>({}setReorderSession(null);},- [announce, commit, setReorderSession, t],+ [announce, commit, isDisabled, setReorderSession, t],);const handleReorderClick = useCallback(@@ -1106,7 +1133,7 @@ export function TransferList<T extends string = string>({<IconButtonlabel={t('@astryx.transferList.reorderOption', {label: option.label})}aria-describedby={reorderInstructionsId}- aria-pressed={active}+ aria-pressed={active && !isDisabled}icon={<Icon icon={GripVerticalIcon} size="sm" />}size="sm"variant="ghost"@@ -1241,6 +1268,7 @@ export function TransferList<T extends string = string>({hasClearwidth="100%"controlXstyle={styles.search}+ isDisabled={isDisabled}onChange={handleSearch}/></div>diff --git a/packages/lab/src/TransferList/TransferListSelector.test.tsx b/packages/lab/src/TransferList/TransferListSelector.test.tsxindex bfdc12a870..82e5629b37 100644--- a/packages/lab/src/TransferList/TransferListSelector.test.tsx+++ b/packages/lab/src/TransferList/TransferListSelector.test.tsx@@ -420,14 +420,16 @@ describe('TransferListSelector', () => {).toHaveTextContent('3 selected');});- it('disables list controls when disabled, but never when merely busy', async () => {+ it('marks list controls disabled without the native attribute, keeping focus, but never when merely busy', async () => {+ const user = userEvent.setup();+ const onChange = vi.fn();const view = render(<TransferListSelectorlabel="Visible fields"options={OPTIONS}value={['name']}- onChange={() => {}}- commitBehavior="staged"+ onChange={onChange}+ hasSearch/>,);await openSelector();@@ -435,20 +437,45 @@ describe('TransferListSelector', () => {name: 'Visible fields',...hidden,});+ const addStatus = within(dialog).getByRole('button', {+ name: 'Add Status',+ hidden: true,+ });+ addStatus.focus();view.rerender(<TransferListSelectorlabel="Visible fields"options={OPTIONS}value={['name']}- onChange={() => {}}- commitBehavior="staged"+ onChange={onChange}isDisabled+ hasSearch/>,);const fieldset = dialog.querySelector('fieldset');expect(fieldset).not.toBeNull();- expect(fieldset).toBeDisabled();+ // A focusable disabled group: no native `disabled`, which would blur the+ // focused control; aria-disabled marks every control in it.+ expect(fieldset).not.toHaveAttribute('disabled');+ expect(fieldset).toHaveAttribute('aria-disabled', 'true');+ expect(addStatus).toHaveFocus();+ await user.click(addStatus);+ expect(onChange).not.toHaveBeenCalled();+ // The search field is disabled but focusable.+ expect(+ within(dialog).getByRole('searchbox', {hidden: true}),+ ).toHaveAttribute('aria-disabled', 'true');+ view.rerender(+ <TransferListSelector+ label="Visible fields"+ options={OPTIONS}+ value={['name']}+ onChange={() => {}}+ commitBehavior="staged"+ isDisabled+ />,+ );const cancel = within(dialog).getByRole('button', {name: 'Cancel',diff --git a/packages/lab/src/TransferList/TransferListSelector.tsx b/packages/lab/src/TransferList/TransferListSelector.tsxindex 4d5f3d94be..fa106bd054 100644--- a/packages/lab/src/TransferList/TransferListSelector.tsx+++ b/packages/lab/src/TransferList/TransferListSelector.tsx@@ -272,7 +272,7 @@ export function TransferListSelector<T extends string = string>({/>)}<fieldset- disabled={isDisabled}+ aria-disabled={isDisabled || undefined}{...stylex.props(styles.fieldset,state.isBusy && styles.fieldsetBusy,@@ -281,8 +281,12 @@ export function TransferListSelector<T extends string = string>({label={label}isLabelHiddenoptions={options}+ isDisabled={isDisabled}value={transferListValue}onChange={nextValue => {+ if (isDisabled) {+ return;+ }// Now that busy no longer disables the fieldset, the controls// stay live while a change is in flight; ignore transfers// until it settles so one pending action cannot be stacked.