Skip to content

Commit

Permalink
Fix #1413/#5836: Dropdown ScreenReader support (#5991)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Feb 16, 2024
1 parent 9cc3b35 commit f7dc3b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ export const Dropdown = React.memo(
const updateEditableLabel = (option) => {
if (inputRef.current) {
inputRef.current.value = option ? getOptionLabel(option) : props.value || '';

// #1413 NVDA screenreader
if (focusInputRef.current) {
focusInputRef.current.value = inputRef.current.value;
}
}
};

Expand Down Expand Up @@ -885,6 +890,11 @@ export const Dropdown = React.memo(
const value = label || props.value || '';

inputRef.current.value = value;

// #1413 NVDA screenreader
if (focusInputRef.current) {
focusInputRef.current.value = value;
}
}
};

Expand Down Expand Up @@ -996,6 +1006,12 @@ export const Dropdown = React.memo(
};

const createKeyboardHelper = () => {
let value = ObjectUtils.isNotEmpty(selectedOption) ? getOptionLabel(selectedOption) : null;

if (props.editable) {
value = value || props.value || '';
}

const hiddenSelectedMessageProps = mergeProps(
{
className: 'p-hidden-accessible'
Expand All @@ -1007,6 +1023,7 @@ export const Dropdown = React.memo(
{
ref: focusInputRef,
id: props.inputId,
defaultValue: value,
type: 'text',
readOnly: true,
'aria-haspopup': 'listbox',
Expand Down

0 comments on commit f7dc3b1

Please sign in to comment.