Skip to content

Commit 745c33f

Browse files
fix(plugin-filtering): update selected item rendering logic and toggle button placement
1 parent 19dce27 commit 745c33f

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

packages/shared/widget-plugin-filtering/src/controllers/picker/mixins/TagPickerControllerMixin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function TagPickerControllerMixin<TBase extends BaseController>(Base: TBa
130130
return;
131131
}
132132
this.filterStore.toggle(selectedItem.value);
133+
this.setInputValue("");
133134
},
134135
stateReducer(state, { changes, type }) {
135136
switch (type) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ export const Combobox = observer(function Combobox(props: ComboboxProps) {
5050
placeholder: props.inputPlaceholder
5151
})}
5252
/>
53-
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
54-
<Arrow className={cls.stateIcon} />
55-
</button>
5653
<ClearButton
5754
cls={cls}
5855
onClick={() => {
@@ -62,6 +59,9 @@ export const Combobox = observer(function Combobox(props: ComboboxProps) {
6259
showSeparator={false}
6360
visible={!props.empty}
6461
/>
62+
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
63+
<Arrow className={cls.stateIcon} />
64+
</button>
6565
<OptionsWrapper
6666
cls={cls}
6767
ref={refs.setFloating}

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ export const Select = observer(function Select(props: SelectProps): React.ReactE
4343
style={props.style}
4444
>
4545
<button
46-
className={cls.toggle}
46+
className={cls.inputContainer}
4747
{...getToggleButtonProps({
4848
"aria-label": props.value,
4949
ref: toggleRef,
5050
onFocus: props.onFocus
5151
})}
5252
>
53-
{props.value}
53+
<span className={cls.toggle}>{props.value}</span>
54+
<ClearButton
55+
cls={cls}
56+
onClick={() => {
57+
props.onClear();
58+
toggleRef.current?.focus();
59+
}}
60+
showSeparator={false}
61+
visible={showClear}
62+
/>
63+
<Arrow className={cls.stateIcon} />
5464
</button>
55-
<ClearButton
56-
cls={cls}
57-
onClick={() => {
58-
props.onClear();
59-
toggleRef.current?.focus();
60-
}}
61-
showSeparator={false}
62-
visible={showClear}
63-
/>
64-
<Arrow className={cls.stateIcon} />
6565
<OptionsWrapper
6666
cls={cls}
6767
ref={refs.setFloating}

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

+16-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
4040
props.useComboboxProps()
4141
);
4242
const { refs, floatingStyles } = useFloatingMenu(isOpen);
43-
const showRemoveItem = selectedStyle === "boxes";
4443

4544
return (
4645
<div
@@ -70,14 +69,14 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
7069
}
7170
}}
7271
>
73-
{props.selected.map((item, index) => (
74-
<div
75-
className={cls.selectedItem}
76-
key={index}
77-
{...getSelectedItemProps({ selectedItem: item, index })}
78-
>
79-
{item.caption}
80-
{showRemoveItem && (
72+
{selectedStyle === "boxes" &&
73+
props.selected.map((item, index) => (
74+
<div
75+
className={cls.selectedItem}
76+
key={index}
77+
{...getSelectedItemProps({ selectedItem: item, index })}
78+
>
79+
{item.caption}
8180
<span
8281
className={cls.removeIcon}
8382
onClick={e => {
@@ -87,9 +86,8 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
8786
>
8887
<Cross width="10" height="10" />
8988
</span>
90-
)}
91-
</div>
92-
))}
89+
</div>
90+
))}
9391
<input
9492
className={cls.input}
9593
{...getInputProps({
@@ -101,19 +99,21 @@ export const TagPicker = observer(function TagPicker(props: TagPickerProps): Rea
10199
"aria-describedby": props.empty ? undefined : `${helperText1} ${inputContainerId}`
102100
})}
103101
/>
102+
{selectedStyle === "text" && props.selected.length > 0 && (
103+
<div className={cls.selectedItem}>{props.selected.map(item => item.caption).join(", ")}</div>
104+
)}
104105
</div>
105-
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
106-
<Arrow className={cls.stateIcon} />
107-
</button>
108106
<ClearButton
109107
cls={cls}
110108
onClick={() => {
111109
props.onClear();
112110
inputRef.current?.focus();
113111
}}
114-
showSeparator
115112
visible={!props.empty}
116113
/>
114+
<button className={cls.toggle} {...getToggleButtonProps({ "aria-label": "Show options" })}>
115+
<Arrow className={cls.stateIcon} />
116+
</button>
117117
<OptionsWrapper
118118
cls={cls}
119119
ref={refs.setFloating}

0 commit comments

Comments
 (0)