Skip to content

Commit

Permalink
Fix Dropdown linting error.
Browse files Browse the repository at this point in the history
  • Loading branch information
aappoalander committed Jun 8, 2021
1 parent 4f67c42 commit 76c0201
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/core/Dropdown/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class BaseDropdown extends Component<DropdownProps & InnerRef> {
: undefined,
};

buttonRef: React.RefObject<HTMLButtonElement>;

constructor(props: DropdownProps & InnerRef) {
super(props);
this.buttonRef = React.createRef();
}

static getDerivedStateFromProps(
nextProps: DropdownProps,
prevState: DropdownState,
Expand Down Expand Up @@ -190,6 +197,7 @@ class BaseDropdown extends Component<DropdownProps & InnerRef> {
value={selectedValue || ''}
>
<ListboxButton
ref={this.buttonRef}
{...dropdownButtonProps}
id={buttonId}
className={classnames(dropdownClassNames.button, {
Expand All @@ -205,6 +213,12 @@ class BaseDropdown extends Component<DropdownProps & InnerRef> {
<ListboxPopover
position={positionMatchWidth}
{...passDropdownPopoverProps}
onKeyDownCapture={(event: KeyboardEvent) => {
if (event.code === 'Tab' && !!this.buttonRef.current) {
event.preventDefault();
this.buttonRef.current.focus();
}
}}
>
<ListboxList>{children}</ListboxList>
</ListboxPopover>
Expand Down

0 comments on commit 76c0201

Please sign in to comment.