Skip to content

Commit 84e1b01

Browse files
yordan-stgjulivan
authored andcommitted
refactor: cleanup
1 parent 34cc45c commit 84e1b01

3 files changed

Lines changed: 16 additions & 22 deletions

File tree

packages/pluggableWidgets/combobox-web/src/components/MultiSelection/MultiSelection.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export function MultiSelection({
1616
a11yConfig,
1717
menuFooterContent,
1818
ariaRequired,
19-
...options
19+
labelId,
20+
inputId,
21+
ariaLabel,
22+
readOnlyStyle,
23+
noOptionsText
2024
}: SelectionBaseProps<MultiSelector>): ReactElement {
2125
const {
2226
isOpen,
@@ -33,11 +37,11 @@ export function MultiSelection({
3337
items,
3438
setSelectedItems,
3539
toggleSelectedItem
36-
} = useDownshiftMultiSelectProps(selector, { ...options }, a11yConfig.a11yStatusMessage);
40+
} = useDownshiftMultiSelectProps(selector, { inputId, labelId }, a11yConfig.a11yStatusMessage);
3741
const inputRef = useRef<HTMLInputElement>(null);
3842
const isSelectedItemsBoxStyle = selector.selectedItemsStyle === "boxes";
3943
const isOptionsSelected = selector.isOptionsSelected();
40-
const inputLabel = getInputLabel(options.inputId);
44+
const inputLabel = getInputLabel(inputId);
4145
const hasLabel = useMemo(() => Boolean(inputLabel), [inputLabel]);
4246
const inputProps = getInputProps({
4347
...getDropdownProps(
@@ -65,7 +69,7 @@ export function MultiSelection({
6569
disabled: selector.readOnly,
6670
readOnly: selector.options.filterType === "none",
6771
"aria-required": ariaRequired.value,
68-
"aria-label": !hasLabel && options.ariaLabel ? options.ariaLabel : undefined
72+
"aria-label": !hasLabel && ariaLabel ? ariaLabel : undefined
6973
});
7074

7175
const memoizedselectedCaptions = useMemo(
@@ -91,7 +95,7 @@ export function MultiSelection({
9195
<ComboboxWrapper
9296
isOpen={isOpen}
9397
readOnly={selector.readOnly}
94-
readOnlyStyle={options.readOnlyStyle}
98+
readOnlyStyle={readOnlyStyle}
9599
getToggleButtonProps={getToggleButtonProps}
96100
validation={selector.validation}
97101
isLoading={lazyLoading && selector.options.isLoading}
@@ -168,7 +172,7 @@ export function MultiSelection({
168172
<SelectAllButton
169173
disabled={items.length === 0}
170174
value={isOptionsSelected}
171-
id={`${options.inputId}-select-all-button`}
175+
id={`${inputId}-select-all-button`}
172176
ariaLabel={a11yConfig.ariaLabels.selectAll}
173177
onChange={() => {
174178
if (isOptionsSelected === "all") {
@@ -181,15 +185,15 @@ export function MultiSelection({
181185
) : undefined
182186
}
183187
menuFooterContent={menuFooterContent}
184-
inputId={options.inputId}
188+
inputId={inputId}
185189
selector={selector}
186190
isOpen={isOpen}
187191
highlightedIndex={highlightedIndex}
188192
selectableItems={items}
189193
getItemProps={getItemProps}
190194
getMenuProps={getMenuProps}
191195
selectedItems={selectedItems}
192-
noOptionsText={options.noOptionsText}
196+
noOptionsText={noOptionsText}
193197
onOptionClick={() => {
194198
inputRef.current?.focus();
195199
}}

packages/pluggableWidgets/combobox-web/src/hooks/useDownshiftMultiSelectProps.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ function useComboboxProps(
153153

154154
if (
155155
selector.onFilterInputChange &&
156-
type &&
157-
(type === "__input_change__" || type.includes("input_change")) &&
156+
type?.includes("input_change") &&
158157
inputValue &&
159-
inputValue.trim().length > 0
158+
inputValue.trim()?.length > 0
160159
) {
161-
selector.onFilterInputChange(inputValue!);
160+
selector.onFilterInputChange(inputValue);
162161
}
163162
},
164163
getA11yStatusMessage(options) {

packages/pluggableWidgets/combobox-web/src/hooks/useGetSelector.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,9 @@ export function useGetSelector(props: ComboboxContainerProps): Selector {
3838
if (!selectorRef.current) {
3939
selectorRef.current = getSelector(props);
4040
selectorRef.current.options.onAfterSearchTermChange(() => setInput({}));
41-
42-
if (props.onChangeFilterInputEvent) {
43-
selectorRef.current.onFilterInputChange = onFilterInputChange;
44-
}
4541
}
4642
selectorRef.current.updateProps(props);
47-
48-
if (props.onChangeFilterInputEvent) {
49-
selectorRef.current.onFilterInputChange = onFilterInputChange;
50-
} else {
51-
selectorRef.current.onFilterInputChange = undefined;
52-
}
43+
selectorRef.current.onFilterInputChange = onFilterInputChange;
5344

5445
return selectorRef.current;
5546
}

0 commit comments

Comments
 (0)