Skip to content

Commit 382649d

Browse files
committed
refactor: a11y MultiSelect
1 parent e8fef17 commit 382649d

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

packages/fuselage/src/components/MultiSelect/MultiSelect.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,25 @@ const MultiSelect = forwardRef<HTMLInputElement, MultiSelectProps>(
146146

147147
const listboxId = props.id ? `${props.id}-listbox` : undefined;
148148

149+
const {
150+
id,
151+
name,
152+
'aria-labelledby': ariaLabelledBy,
153+
'aria-describedby': ariaDescribedBy,
154+
'aria-invalid': ariaInvalid,
155+
'aria-required': ariaRequired,
156+
...containerProps
157+
} = props;
158+
149159
return (
150160
<Box
151161
is='div'
152162
rcx-select
153-
role='combobox'
154-
aria-expanded={visible === AnimatedVisibility.VISIBLE}
155-
aria-haspopup='listbox'
156-
aria-controls={listboxId}
157163
className={[error && 'invalid', disabled && 'disabled']}
158164
ref={containerRef}
159165
onClick={handleClick}
160166
disabled={disabled}
161-
{...props}
167+
{...containerProps}
162168
>
163169
<FlexItem grow={1}>
164170
<Margins inline='x4'>
@@ -173,13 +179,24 @@ const MultiSelect = forwardRef<HTMLInputElement, MultiSelectProps>(
173179
>
174180
<Margins all='x4'>
175181
{renderAnchor({
176-
ref: anchorRef,
177-
children: internalValue.length === 0 ? placeholder : null,
178-
disabled: disabled ?? false,
179-
onClick: show,
180-
onBlur: hide,
181-
onKeyDown: handleKeyDown,
182-
onKeyUp: handleKeyUp,
182+
'ref': anchorRef,
183+
'children':
184+
internalValue.length === 0 ? placeholder : null,
185+
'disabled': disabled ?? false,
186+
'onClick': show,
187+
'onBlur': hide,
188+
'onKeyDown': handleKeyDown,
189+
'onKeyUp': handleKeyUp,
190+
'role': 'combobox',
191+
'aria-expanded': visible === AnimatedVisibility.VISIBLE,
192+
'aria-haspopup': 'listbox',
193+
'aria-controls': listboxId,
194+
id,
195+
name,
196+
'aria-labelledby': ariaLabelledBy,
197+
'aria-describedby': ariaDescribedBy,
198+
'aria-invalid': ariaInvalid,
199+
'aria-required': ariaRequired,
183200
})}
184201
{internalValue.map((value: SelectOption[0]) => {
185202
const currentOption = options.find(

packages/fuselage/src/components/MultiSelect/MultiSelectAnchor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
AriaAttributes,
23
FocusEventHandler,
34
KeyboardEventHandler,
45
MouseEventHandler,
@@ -15,7 +16,10 @@ type MultiSelectAnchorProps = {
1516
onBlur: FocusEventHandler;
1617
onKeyUp: KeyboardEventHandler;
1718
onKeyDown: KeyboardEventHandler;
18-
};
19+
role?: string;
20+
id?: string;
21+
name?: string;
22+
} & AriaAttributes;
1923

2024
const MultiSelectAnchor = forwardRef<Element, MultiSelectAnchorProps>(
2125
function MultiSelectAnchor({ children, ...props }, ref) {

packages/fuselage/src/components/MultiSelect/MultiSelectAnchorParams.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ export type MultiSelectAnchorParams = {
1515
onBlur: FocusEventHandler;
1616
onKeyUp: KeyboardEventHandler;
1717
onKeyDown: KeyboardEventHandler;
18+
role?: string;
19+
id?: string;
1820
name?: string;
1921
} & AriaAttributes;

packages/fuselage/src/components/MultiSelect/MultiSelectFilteredAnchor.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
AriaAttributes,
23
FocusEventHandler,
34
FormEvent,
45
KeyboardEventHandler,
@@ -20,7 +21,10 @@ type MultiSelectFilteredAnchorProps = {
2021
onBlur: FocusEventHandler;
2122
onKeyUp: KeyboardEventHandler;
2223
onKeyDown: KeyboardEventHandler;
23-
};
24+
role?: string;
25+
id?: string;
26+
name?: string;
27+
} & AriaAttributes;
2428

2529
const MultiSelectFilteredAnchor = forwardRef<
2630
HTMLInputElement,

0 commit comments

Comments
 (0)