@zenkigen-inc/component-ui 1.21.0 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -116,6 +116,12 @@ type ComboboxProps = PropsWithChildren<{
116
116
  inputValue: string;
117
117
  /** 入力変更時のコールバック */
118
118
  onInputChange: (value: string) => void;
119
+ /**
120
+ * クリアボタンのクリック時に呼ばれるコールバック。
121
+ * このコールバックを渡したときのみクリアボタンが表示される(TextInput と同一仕様)。
122
+ * 値のクリア(`onChange(null, null)` / `onInputChange('')`)は利用者側で行う。
123
+ */
124
+ onClickClearButton?: () => void;
119
125
  /** popup の開閉状態(任意、controlled) */
120
126
  isOpen?: boolean;
121
127
  /** 開閉変更時のコールバック */
@@ -165,7 +171,7 @@ declare function ComboboxList({ children, maxHeight: maxHeightProp }: ComboboxLi
165
171
  declare function ComboboxLoading(): react.JSX.Element;
166
172
  declare function ComboboxEmpty(): react.JSX.Element;
167
173
 
168
- declare function ComboboxBase({ children, value, onChange, inputValue, onInputChange, isOpen: isOpenProp, onOpenChange, size, variant, placeholder, isError, isDisabled, width, maxWidth, listMaxHeight, matchListToTrigger, }: ComboboxProps): react.JSX.Element;
174
+ declare function ComboboxBase({ children, value, onChange, inputValue, onInputChange, onClickClearButton, isOpen: isOpenProp, onOpenChange, size, variant, placeholder, isError, isDisabled, width, maxWidth, listMaxHeight, matchListToTrigger, }: ComboboxProps): react.JSX.Element;
169
175
  declare const Combobox: typeof ComboboxBase & {
170
176
  Input: typeof ComboboxInput;
171
177
  List: typeof ComboboxList;
package/dist/index.d.ts CHANGED
@@ -116,6 +116,12 @@ type ComboboxProps = PropsWithChildren<{
116
116
  inputValue: string;
117
117
  /** 入力変更時のコールバック */
118
118
  onInputChange: (value: string) => void;
119
+ /**
120
+ * クリアボタンのクリック時に呼ばれるコールバック。
121
+ * このコールバックを渡したときのみクリアボタンが表示される(TextInput と同一仕様)。
122
+ * 値のクリア(`onChange(null, null)` / `onInputChange('')`)は利用者側で行う。
123
+ */
124
+ onClickClearButton?: () => void;
119
125
  /** popup の開閉状態(任意、controlled) */
120
126
  isOpen?: boolean;
121
127
  /** 開閉変更時のコールバック */
@@ -165,7 +171,7 @@ declare function ComboboxList({ children, maxHeight: maxHeightProp }: ComboboxLi
165
171
  declare function ComboboxLoading(): react.JSX.Element;
166
172
  declare function ComboboxEmpty(): react.JSX.Element;
167
173
 
168
- declare function ComboboxBase({ children, value, onChange, inputValue, onInputChange, isOpen: isOpenProp, onOpenChange, size, variant, placeholder, isError, isDisabled, width, maxWidth, listMaxHeight, matchListToTrigger, }: ComboboxProps): react.JSX.Element;
174
+ declare function ComboboxBase({ children, value, onChange, inputValue, onInputChange, onClickClearButton, isOpen: isOpenProp, onOpenChange, size, variant, placeholder, isError, isDisabled, width, maxWidth, listMaxHeight, matchListToTrigger, }: ComboboxProps): react.JSX.Element;
169
175
  declare const Combobox: typeof ComboboxBase & {
170
176
  Input: typeof ComboboxInput;
171
177
  List: typeof ComboboxList;
package/dist/index.js CHANGED
@@ -746,9 +746,9 @@ function ComboboxInput({ autoFocus, children }) {
746
746
  setInputElementRef,
747
747
  handleKeyDown,
748
748
  handleInputBlur,
749
- clearValue
749
+ onClickClearButton
750
750
  } = useComboboxContext("Combobox.Input");
751
- const isClearButtonVisible = inputValue.length > 0 && !isDisabled;
751
+ const isClearButtonVisible = onClickClearButton != null && inputValue.length > 0 && !isDisabled;
752
752
  const isEffectivelyOpen = isOpen && hasOpenableContent2;
753
753
  const activeItem = activeIndex !== null ? items[activeIndex] : null;
754
754
  const activeId = activeItem != null ? `${baseId}-option-${activeItem.value}` : null;
@@ -767,8 +767,8 @@ function ComboboxInput({ autoFocus, children }) {
767
767
  inputRef.current?.focus();
768
768
  }, [isOpen, setIsOpen, inputRef]);
769
769
  const handleClear = (0, import_react10.useCallback)(() => {
770
- clearValue();
771
- }, [clearValue]);
770
+ onClickClearButton?.();
771
+ }, [onClickClearButton]);
772
772
  const setRef = (0, import_react10.useCallback)(
773
773
  (node) => {
774
774
  setInputElementRef(node);
@@ -1260,14 +1260,12 @@ function useCombobox(params) {
1260
1260
  },
1261
1261
  [setIsOpen]
1262
1262
  );
1263
- const clearValue = (0, import_react17.useCallback)(() => {
1264
- committedInputValueRef.current = "";
1265
- paramsRef.current.onChange(null, null);
1266
- paramsRef.current.onInputChange("");
1267
- setActiveIndexState(null);
1268
- activeValueRef.current = null;
1269
- inputRef.current?.focus();
1270
- }, []);
1263
+ (0, import_react17.useEffect)(() => {
1264
+ if (params.inputValue === "" && params.value === null) {
1265
+ setActiveIndexState(null);
1266
+ activeValueRef.current = null;
1267
+ }
1268
+ }, [params.inputValue, params.value]);
1271
1269
  const moveActive = (0, import_react17.useCallback)((direction) => {
1272
1270
  const currentItems = itemsRef.current;
1273
1271
  const enabledIndices = currentItems.flatMap((item, i) => item.isDisabled ? [] : [i]);
@@ -1365,7 +1363,6 @@ function useCombobox(params) {
1365
1363
  items,
1366
1364
  setItems,
1367
1365
  selectValue,
1368
- clearValue,
1369
1366
  revertInputToCommitted,
1370
1367
  inputRef,
1371
1368
  handleKeyDown
@@ -1389,6 +1386,7 @@ function ComboboxBase({
1389
1386
  onChange,
1390
1387
  inputValue,
1391
1388
  onInputChange,
1389
+ onClickClearButton,
1392
1390
  isOpen: isOpenProp,
1393
1391
  onOpenChange,
1394
1392
  size = "medium",
@@ -1507,7 +1505,7 @@ function ComboboxBase({
1507
1505
  setIsOpen,
1508
1506
  selectedValue: value,
1509
1507
  selectValue: combobox.selectValue,
1510
- clearValue: combobox.clearValue,
1508
+ onClickClearButton,
1511
1509
  activeIndex: combobox.activeIndex,
1512
1510
  setActiveIndex: combobox.setActiveIndex,
1513
1511
  inputMode: combobox.inputMode,
@@ -1538,7 +1536,7 @@ function ComboboxBase({
1538
1536
  setIsOpen,
1539
1537
  value,
1540
1538
  combobox.selectValue,
1541
- combobox.clearValue,
1539
+ onClickClearButton,
1542
1540
  combobox.activeIndex,
1543
1541
  combobox.setActiveIndex,
1544
1542
  combobox.inputMode,
package/dist/index.mjs CHANGED
@@ -665,9 +665,9 @@ function ComboboxInput({ autoFocus, children }) {
665
665
  setInputElementRef,
666
666
  handleKeyDown,
667
667
  handleInputBlur,
668
- clearValue
668
+ onClickClearButton
669
669
  } = useComboboxContext("Combobox.Input");
670
- const isClearButtonVisible = inputValue.length > 0 && !isDisabled;
670
+ const isClearButtonVisible = onClickClearButton != null && inputValue.length > 0 && !isDisabled;
671
671
  const isEffectivelyOpen = isOpen && hasOpenableContent2;
672
672
  const activeItem = activeIndex !== null ? items[activeIndex] : null;
673
673
  const activeId = activeItem != null ? `${baseId}-option-${activeItem.value}` : null;
@@ -686,8 +686,8 @@ function ComboboxInput({ autoFocus, children }) {
686
686
  inputRef.current?.focus();
687
687
  }, [isOpen, setIsOpen, inputRef]);
688
688
  const handleClear = useCallback2(() => {
689
- clearValue();
690
- }, [clearValue]);
689
+ onClickClearButton?.();
690
+ }, [onClickClearButton]);
691
691
  const setRef = useCallback2(
692
692
  (node) => {
693
693
  setInputElementRef(node);
@@ -1179,14 +1179,12 @@ function useCombobox(params) {
1179
1179
  },
1180
1180
  [setIsOpen]
1181
1181
  );
1182
- const clearValue = useCallback4(() => {
1183
- committedInputValueRef.current = "";
1184
- paramsRef.current.onChange(null, null);
1185
- paramsRef.current.onInputChange("");
1186
- setActiveIndexState(null);
1187
- activeValueRef.current = null;
1188
- inputRef.current?.focus();
1189
- }, []);
1182
+ useEffect4(() => {
1183
+ if (params.inputValue === "" && params.value === null) {
1184
+ setActiveIndexState(null);
1185
+ activeValueRef.current = null;
1186
+ }
1187
+ }, [params.inputValue, params.value]);
1190
1188
  const moveActive = useCallback4((direction) => {
1191
1189
  const currentItems = itemsRef.current;
1192
1190
  const enabledIndices = currentItems.flatMap((item, i) => item.isDisabled ? [] : [i]);
@@ -1284,7 +1282,6 @@ function useCombobox(params) {
1284
1282
  items,
1285
1283
  setItems,
1286
1284
  selectValue,
1287
- clearValue,
1288
1285
  revertInputToCommitted,
1289
1286
  inputRef,
1290
1287
  handleKeyDown
@@ -1308,6 +1305,7 @@ function ComboboxBase({
1308
1305
  onChange,
1309
1306
  inputValue,
1310
1307
  onInputChange,
1308
+ onClickClearButton,
1311
1309
  isOpen: isOpenProp,
1312
1310
  onOpenChange,
1313
1311
  size = "medium",
@@ -1426,7 +1424,7 @@ function ComboboxBase({
1426
1424
  setIsOpen,
1427
1425
  selectedValue: value,
1428
1426
  selectValue: combobox.selectValue,
1429
- clearValue: combobox.clearValue,
1427
+ onClickClearButton,
1430
1428
  activeIndex: combobox.activeIndex,
1431
1429
  setActiveIndex: combobox.setActiveIndex,
1432
1430
  inputMode: combobox.inputMode,
@@ -1457,7 +1455,7 @@ function ComboboxBase({
1457
1455
  setIsOpen,
1458
1456
  value,
1459
1457
  combobox.selectValue,
1460
- combobox.clearValue,
1458
+ onClickClearButton,
1461
1459
  combobox.activeIndex,
1462
1460
  combobox.setActiveIndex,
1463
1461
  combobox.inputMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenkigen-inc/component-ui",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "repository": "https://github.com/zenkigen/zenkigen-component",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -38,9 +38,9 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@floating-ui/react": "0.27.19",
41
- "@zenkigen-inc/component-config": "1.21.0",
42
- "@zenkigen-inc/component-icons": "1.21.0",
43
- "@zenkigen-inc/component-theme": "1.21.0",
41
+ "@zenkigen-inc/component-config": "1.21.1",
42
+ "@zenkigen-inc/component-icons": "1.21.1",
43
+ "@zenkigen-inc/component-theme": "1.21.1",
44
44
  "clsx": "2.1.1",
45
45
  "react-day-picker": "9.14.0"
46
46
  }