diff --git a/ui/src/shared/components/Dropdown.tsx b/ui/src/shared/components/Dropdown.tsx index 7651aba22..c8a169ba7 100644 --- a/ui/src/shared/components/Dropdown.tsx +++ b/ui/src/shared/components/Dropdown.tsx @@ -78,7 +78,11 @@ export class Dropdown extends Component { } public handleHighlight = (itemIndex: number) => () => { - this.setState({highlightedItemIndex: itemIndex}) + // setup highlighted element only in auto-complete mode, + // otherwise rely upon CSS :hover highlighting + if (this.props.useAutoComplete) { + this.setState({highlightedItemIndex: itemIndex}) + } } public toggleMenu = (e?: MouseEvent) => { @@ -158,6 +162,10 @@ export class Dropdown extends Component { }) } + private setDropdownRef = (ref: any) => { + this.dropdownRef = ref + } + public render() { const { items, @@ -188,7 +196,7 @@ export class Dropdown extends Component { [className]: className, })} tabIndex={tabIndex} - ref={r => (this.dropdownRef = r)} + ref={this.setDropdownRef} data-test="dropdown-toggle" > {useAutoComplete && isOpen ? ( diff --git a/ui/src/shared/components/DropdownMenu.tsx b/ui/src/shared/components/DropdownMenu.tsx index c57938703..011d4c1e5 100644 --- a/ui/src/shared/components/DropdownMenu.tsx +++ b/ui/src/shared/components/DropdownMenu.tsx @@ -108,7 +108,11 @@ const DropdownMenu: FunctionComponent = ({ autoHeight={true} maxHeight={DROPDOWN_MENU_MAX_HEIGHT} > - {menuLabel ?
  • {menuLabel}
  • : null} + {menuLabel ? ( +
  • + {menuLabel} +
  • + ) : null} {items.map((item, i) => ( = ({ +const DropdownMenuItem = ({ item, highlightedItemIndex, onSelection, @@ -37,7 +37,7 @@ const DropdownMenuItem: FunctionComponent = ({ onAction, selected, index, -}) => { +}: ItemProps) => { if (_.isString(item)) { item = {text: item} } @@ -46,6 +46,14 @@ const DropdownMenuItem: FunctionComponent = ({ return
  • } + const onClick = useCallback( + (e: MouseEvent) => { + e.preventDefault() + onSelection(item)(e) + }, + [item] + ) + return (
  • = ({ })} data-test={`${item.text}-dropdown-item`} > - + {item.text} {actions && !!actions.length && ( diff --git a/ui/src/style/theme/_dropdowns.scss b/ui/src/style/theme/_dropdowns.scss index e88884365..18dc815ee 100644 --- a/ui/src/style/theme/_dropdowns.scss +++ b/ui/src/style/theme/_dropdowns.scss @@ -69,7 +69,6 @@ $dropdown-purple-header: $c-potassium; &-340 .dropdown-toggle {width: 340px;} } -.dropdown:focus, .dropdown.open, .dropdown.open:focus { outline: none;