Skip to content

Commit 0277428

Browse files
committed
chore: restructure select html layout, don't use button, move toggle button up the html tree
- makes it easier to open the popup, previously it was not opening if clicked inside, but next to the border. - fixes issue with nested button tags.
1 parent 2a88697 commit 0277428

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

packages/shared/widget-plugin-dropdown-filter/src/controls/base/OptionsWrapper.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ export const OptionsWrapper = forwardRef((props: OptionsWrapperProps, ref: RefOb
3939
data-highlighted={highlightedIndex === index || undefined}
4040
key={item.value || index}
4141
className={cls.menuItem}
42-
{...getItemProps({ item, index, "aria-selected": item.selected })}
42+
{...getItemProps({
43+
item,
44+
index,
45+
"aria-selected": item.selected,
46+
onClick: e => {
47+
e.stopPropagation();
48+
}
49+
})}
4350
>
4451
{showCheckboxes && (
4552
<span className={cls.checkboxSlot}>

packages/shared/widget-plugin-dropdown-filter/src/controls/select/Select.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cn from "classnames";
22
import { useSelect, UseSelectProps } from "downshift";
33
import { observer } from "mobx-react-lite";
4-
import React, { createElement, useRef } from "react";
4+
import React, { createElement } from "react";
55
import { OptionWithState } from "../../typings/OptionWithState";
66
import { ClearButton } from "../base/ClearButton";
77
import { OptionsWrapper } from "../base/OptionsWrapper";
@@ -18,15 +18,14 @@ interface SelectProps {
1818
style?: React.CSSProperties;
1919
useSelectProps: () => UseSelectProps<OptionWithState>;
2020
onClear: () => void;
21-
onFocus?: React.FocusEventHandler<HTMLButtonElement>;
21+
onFocus?: React.FocusEventHandler<HTMLDivElement>;
2222
onMenuScroll?: React.UIEventHandler<HTMLUListElement>;
2323
}
2424

2525
const cls = classes();
2626

2727
export const Select = observer(function Select(props: SelectProps): React.ReactElement {
2828
const { empty: isEmpty, showCheckboxes, clearable } = props;
29-
const toggleRef = useRef<HTMLButtonElement>(null);
3029
const { getToggleButtonProps, getMenuProps, getItemProps, isOpen, highlightedIndex } = useSelect(
3130
props.useSelectProps()
3231
);
@@ -37,25 +36,22 @@ export const Select = observer(function Select(props: SelectProps): React.ReactE
3736
return (
3837
<div
3938
className={cn(cls.root, "form-control", "variant-select", props.className)}
40-
ref={refs.setReference}
4139
data-expanded={isOpen}
4240
data-empty={isEmpty ? true : undefined}
4341
style={props.style}
42+
{...getToggleButtonProps({
43+
"aria-label": props.value,
44+
ref: refs.setReference,
45+
onFocus: props.onFocus
46+
})}
4447
>
45-
<button
46-
className={cls.inputContainer}
47-
{...getToggleButtonProps({
48-
"aria-label": props.value,
49-
ref: toggleRef,
50-
onFocus: props.onFocus
51-
})}
52-
>
48+
<div className={cls.inputContainer}>
5349
<span className={cls.toggle}>{props.value}</span>
5450
<div className={`${cls.root}-controls`}>
5551
<ClearButton cls={cls} onClick={props.onClear} visible={showClear} />
5652
<Arrow className={cls.stateIcon} />
5753
</div>
58-
</button>
54+
</div>
5955
<OptionsWrapper
6056
cls={cls}
6157
ref={refs.setFloating}

0 commit comments

Comments
 (0)