Skip to content

Commit 4ab02b4

Browse files
committed
feat: add onClear callback
1 parent f433574 commit 4ab02b4

File tree

8 files changed

+37
-1
lines changed

8 files changed

+37
-1
lines changed

.changeset/odd-wasps-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Make Panel placeSelf stretch by default.

.changeset/perfect-dancers-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix Item interface for FilterPicker.

.changeset/pretty-comics-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Add onClear callback for FilterPicker, Select, ComboBox and SearchInput.

src/components/fields/ComboBox/ComboBox.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ export interface CubeComboBoxProps<T>
130130
allowsCustomValue?: boolean;
131131
/** Whether the combo box is clearable using ESC keyboard button or clear button inside the input */
132132
isClearable?: boolean;
133+
/** Callback called when the clear button is pressed */
134+
onClear?: () => void;
133135
}
134136

135137
const PROP_STYLES = [...BASE_STYLES, ...OUTER_STYLES, ...COLOR_STYLES];
@@ -336,6 +338,8 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
336338
}
337339
// Focus back to the input
338340
inputRef.current?.focus();
341+
342+
props.onClear?.();
339343
});
340344

341345
let comboBoxWidth = wrapperRef?.current?.offsetWidth;

src/components/fields/FilterPicker/FilterPicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export interface CubeFilterPickerProps<T>
123123
mods?: Record<string, boolean>;
124124
/** Whether the filter picker is clearable using a clear button in the rightIcon slot */
125125
isClearable?: boolean;
126+
/** Callback called when the clear button is pressed */
127+
onClear?: () => void;
126128
}
127129

128130
const PROP_STYLES = [...BASE_STYLES, ...OUTER_STYLES, ...COLOR_STYLES];
@@ -982,6 +984,8 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
982984

983985
triggerRef?.current?.focus?.();
984986

987+
props.onClear?.();
988+
985989
return false;
986990
});
987991

src/components/fields/SearchInput/SearchInput.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface CubeSearchInputProps
2020
SearchFieldProps {
2121
/** Whether the search input is clearable using ESC keyboard button or clear button inside the input */
2222
isClearable?: boolean;
23+
/** Callback called when the clear button is pressed */
24+
onClear?: () => void;
2325
}
2426

2527
export const SearchInput = forwardRef(function SearchInput(
@@ -29,7 +31,7 @@ export const SearchInput = forwardRef(function SearchInput(
2931
props = castNullableStringValue(props);
3032
props = useProviderProps(props);
3133

32-
let { isClearable, validationState } = props;
34+
let { isClearable, validationState, onClear } = props;
3335

3436
let inputRef = useRef(null);
3537

@@ -57,6 +59,12 @@ export const SearchInput = forwardRef(function SearchInput(
5759
type={validationState === 'invalid' ? 'clear' : 'neutral'}
5860
theme={validationState === 'invalid' ? 'danger' : undefined}
5961
{...ariaToCubeButtonProps(clearButtonProps)}
62+
onPress={(e) => {
63+
// Call the original clear functionality
64+
clearButtonProps.onPress?.();
65+
// Call the onClear callback
66+
onClear?.();
67+
}}
6068
/>
6169
)}
6270
</>

src/components/fields/Select/Select.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ export interface CubeSelectBaseProps<T>
204204
theme?: 'default' | 'special';
205205
/** Whether the select is clearable using a clear button in the rightIcon slot */
206206
isClearable?: boolean;
207+
/** Callback called when the clear button is pressed */
208+
onClear?: () => void;
207209
}
208210

209211
export interface CubeSelectProps<T> extends CubeSelectBaseProps<T> {
@@ -351,6 +353,8 @@ function Select<T extends object>(
351353
}
352354
// Return focus to the trigger for better UX
353355
triggerRef.current?.focus?.();
356+
357+
props.onClear?.();
354358
});
355359

356360
let triggerWidth = triggerRef?.current?.offsetWidth;

src/components/layout/Panel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const PanelElement = tasty({
3737
card: '1bw',
3838
},
3939
flexGrow: 1,
40+
placeSelf: 'stretch',
4041
},
4142
});
4243

0 commit comments

Comments
 (0)