Skip to content

Commit 7b63b01

Browse files
committed
fix: focusing issues after clear
1 parent 357e1d2 commit 7b63b01

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type ClearButtonProps = {
1313
visible: boolean;
1414
};
1515

16+
const stopKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
17+
e.stopPropagation();
18+
};
19+
1620
export function ClearButton(props: ClearButtonProps): ReactElement | null {
1721
const { cls, onClick, visible } = props;
1822

@@ -28,7 +32,7 @@ export function ClearButton(props: ClearButtonProps): ReactElement | null {
2832
);
2933

3034
return visible ? (
31-
<button className={cls.clear} aria-label="Clear selection" onClick={onClickHandler}>
35+
<button className={cls.clear} aria-label="Clear selection" onClick={onClickHandler} onKeyDown={stopKeyDown}>
3236
<Cross className={cls.clearIcon} />
3337
</button>
3438
) : null;

packages/shared/widget-plugin-dropdown-filter/src/controls/combobox/Combobox.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ export const Combobox = observer(function Combobox(props: ComboboxProps) {
5151
placeholder: props.empty ? (isOpen ? props.inputPlaceholder : props.emptyCaption) : undefined
5252
})}
5353
/>
54-
<ClearButton cls={cls} onClick={props.onClear} visible={!props.empty} />
54+
<ClearButton
55+
cls={cls}
56+
onClick={() => {
57+
props.onClear();
58+
inputRef.current?.focus();
59+
}}
60+
visible={!props.empty}
61+
/>
5562
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
5663
<Arrow className={cls.stateIcon} />
5764
</button>

packages/shared/widget-plugin-dropdown-filter/src/controls/hooks/useFloatingMenu.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { useMemo } from "react";
2-
import { autoUpdate, size, useFloating } from "@floating-ui/react-dom";
2+
import { autoUpdate, size, useFloating, ReferenceType } from "@floating-ui/react-dom";
33

4-
export function useFloatingMenu(open: boolean): ReturnType<typeof useFloating> {
4+
export function useFloatingMenu<T extends ReferenceType = HTMLDivElement>(
5+
open: boolean
6+
): ReturnType<typeof useFloating<T>> {
57
const middleware = useMemo(
68
() => [
79
size({
@@ -15,7 +17,7 @@ export function useFloatingMenu(open: boolean): ReturnType<typeof useFloating> {
1517
[]
1618
);
1719

18-
return useFloating({
20+
return useFloating<T>({
1921
open,
2022
placement: "bottom-start",
2123
strategy: "fixed",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ export const Select = observer(function Select(props: SelectProps): React.ReactE
4949
<div className={cls.inputContainer}>
5050
<span className={cls.toggle}>{props.value}</span>
5151
<div className={`${cls.root}-controls`}>
52-
<ClearButton cls={cls} onClick={props.onClear} visible={showClear} />
52+
<ClearButton
53+
cls={cls}
54+
onClick={() => {
55+
props.onClear();
56+
refs.reference.current?.focus();
57+
}}
58+
visible={showClear}
59+
/>
5360
<Arrow className={cls.stateIcon} />
5461
</div>
5562
</div>

packages/shared/widget-plugin-dropdown-filter/src/controls/tag-picker/TagPicker.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
113113
</div>
114114
)}
115115
</div>
116-
<ClearButton cls={cls} onClick={props.onClear} visible={!props.empty} />
116+
<ClearButton
117+
cls={cls}
118+
onClick={() => {
119+
props.onClear();
120+
inputContainerRef.current?.querySelector("input")?.focus();
121+
}}
122+
visible={!props.empty}
123+
/>
117124
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
118125
<Arrow className={cls.stateIcon} />
119126
</button>

0 commit comments

Comments
 (0)