Skip to content

Commit

Permalink
fix(dropdown): announce required and read-only status to a11y tree
Browse files Browse the repository at this point in the history
  • Loading branch information
nantunes authored and zettca committed Aug 16, 2023
1 parent 94ed1cf commit 42eb9ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/components/BaseDropdown/BaseDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export interface HvBaseDropdownProps
* If `true` the dropdown will be in read only mode, unable to be interacted.
*/
readOnly?: boolean;
/**
* Indicates that user input is required on the form element.
*/
required?: boolean;
/**
* Disable the portal behavior.
* The children stay within it's parent DOM hierarchy.
Expand Down Expand Up @@ -139,6 +143,7 @@ export const HvBaseDropdown = (props: HvBaseDropdownProps) => {
defaultExpanded = false,
disabled = false,
readOnly = false,
required = false,
disablePortal = false,
variableWidth = false,
placement = "right",
Expand Down Expand Up @@ -366,6 +371,8 @@ export const HvBaseDropdown = (props: HvBaseDropdownProps) => {
}
aria-label={others["aria-label"] ?? undefined}
aria-labelledby={others["aria-labelledby"] ?? undefined}
aria-required={required ?? undefined}
aria-readonly={readOnly ?? undefined}
// Removes the element from the navigation sequence for keyboard focus if disabled
tabIndex={disabled ? -1 : 0}
ref={handleDropdownHeaderRef}
Expand Down Expand Up @@ -490,6 +497,8 @@ export const HvBaseDropdown = (props: HvBaseDropdownProps) => {
role={ariaRole}
aria-expanded={ariaExpanded}
aria-owns={isOpen ? setId(elementId, "children-container") : undefined}
aria-required={required ?? undefined}
aria-readonly={readOnly ?? undefined}
className={cx(
classes.anchor,
{ [classes.rootDisabled]: disabled },
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export const HvDropdown = (props: HvDropdownProps) => {
expanded={isOpen}
disabled={disabled}
readOnly={readOnly}
required={required}
disablePortal={disablePortal}
placement={placement}
popperProps={popperProps}
Expand Down

0 comments on commit 42eb9ff

Please sign in to comment.