Skip to content

Commit

Permalink
Add disabled prop to DropdownCore so that it's interactions can be di…
Browse files Browse the repository at this point in the history
…sabled if it is true. This is needed now that the dropdown opener could potentially not have the disabled attribute set (since we use aria-disabled now on the selectopener so that it can be focusable
  • Loading branch information
beaesguerra committed Jun 11, 2024
1 parent 0fbd580 commit a1957bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/wonder-blocks-dropdown/src/components/dropdown-core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ type ExportProps = Readonly<{
* top. The items will be filtered by the input.
*/
isFilterable?: boolean;
/**
* Whether the dropdown and it's interactions should be disabled.
*/
disabled?: boolean;

// Optional props with defaults
/**
Expand Down Expand Up @@ -1040,12 +1044,12 @@ class DropdownCore extends React.Component<Props, State> {
}

render(): React.ReactNode {
const {open, opener, style, className} = this.props;
const {open, opener, style, className, disabled} = this.props;

return (
<View
onKeyDown={this.handleKeyDown}
onKeyUp={this.handleKeyUp}
onKeyDown={!disabled ? this.handleKeyDown : undefined}
onKeyUp={!disabled ? this.handleKeyUp : undefined}
style={[styles.menuWrapper, style]}
className={className}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ export default class MultiSelect extends React.Component<Props, State> {
isFilterable,
"aria-invalid": ariaInvalid,
"aria-required": ariaRequired,
disabled,
} = this.props;
const {open, searchText} = this.state;
const {clearSearch, filter, noResults, someSelected} =
Expand Down Expand Up @@ -599,6 +600,7 @@ export default class MultiSelect extends React.Component<Props, State> {
}}
aria-invalid={ariaInvalid}
aria-required={ariaRequired}
disabled={disabled}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export default class SingleSelect extends React.Component<Props, State> {
style,
"aria-invalid": ariaInvalid,
"aria-required": ariaRequired,
disabled,
} = this.props;
const {searchText} = this.state;
const allChildren = React.Children.toArray(children).filter(Boolean);
Expand Down Expand Up @@ -484,6 +485,7 @@ export default class SingleSelect extends React.Component<Props, State> {
labels={labels}
aria-invalid={ariaInvalid}
aria-required={ariaRequired}
disabled={disabled}
/>
);
}
Expand Down

0 comments on commit a1957bc

Please sign in to comment.