Skip to content

Commit c04117d

Browse files
(Picklist, Lookup): use inputs with type="text" for better a11y
1 parent c614f48 commit c04117d

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/scripts/Lookup.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,18 @@ const LookupSelectedState: FC<LookupSelectedStateProps> = ({
152152
size='small'
153153
/>
154154
)}
155-
<button
156-
type='button'
155+
<input
156+
type='text'
157+
readOnly
158+
disabled={disabled}
159+
value={selected.label}
157160
role='combobox'
158161
tabIndex={disabled ? -1 : 0}
159162
className='slds-input_faux slds-combobox__input slds-combobox__input-value'
160163
aria-controls={listboxId}
161164
aria-haspopup='listbox'
162165
aria-expanded='false'
163-
>
164-
<span className='slds-truncate'>{selected.label}</span>
165-
</button>
166+
/>
166167
<Button
167168
type='icon'
168169
icon='close'

src/scripts/Picklist.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export type PicklistProps<MultiSelect extends boolean | undefined> = {
209209
tooltip?: ReactNode;
210210
tooltipIcon?: string;
211211
elementRef?: Ref<HTMLDivElement>;
212-
buttonRef?: Ref<HTMLButtonElement>;
212+
inputRef?: Ref<HTMLInputElement>;
213213
dropdownRef?: Ref<HTMLDivElement>;
214214
onValueChange?: Bivariant<
215215
(
@@ -251,7 +251,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
251251
tooltip,
252252
tooltipIcon,
253253
elementRef: elementRef_,
254-
buttonRef: buttonRef_,
254+
inputRef: inputRef_,
255255
dropdownRef: dropdownRef_,
256256
onSelect,
257257
onComplete,
@@ -373,8 +373,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
373373

374374
const elRef = useRef<HTMLDivElement | null>(null);
375375
const elementRef = useMergeRefs([elRef, elementRef_]);
376-
const comboboxElRef = useRef<HTMLButtonElement | null>(null);
377-
const buttonRef = useMergeRefs([comboboxElRef, buttonRef_]);
376+
const comboboxElRef = useRef<HTMLInputElement | null>(null);
377+
const inputRef = useMergeRefs([comboboxElRef, inputRef_]);
378378
const dropdownElRef = useRef<HTMLDivElement | null>(null);
379379
const dropdownRef = useMergeRefs([dropdownElRef, dropdownRef_]);
380380

@@ -607,9 +607,9 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
607607
className='slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right'
608608
role='none'
609609
>
610-
<button
611-
type='button'
612-
ref={buttonRef}
610+
<input
611+
type='text'
612+
ref={inputRef}
613613
role='combobox'
614614
tabIndex={disabled ? -1 : 0}
615615
className={inputClassNames}
@@ -624,9 +624,10 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
624624
onKeyDown={onKeyDown}
625625
onBlur={onBlur}
626626
{...rprops}
627-
>
628-
<span className='slds-truncate'>{selectedItemLabel}</span>
629-
</button>
627+
value={selectedItemLabel}
628+
readOnly
629+
disabled={disabled}
630+
/>
630631
<Icon
631632
containerClassName='slds-input__icon slds-input__icon_right'
632633
category='utility'

0 commit comments

Comments
 (0)