@robert-stackflow/oneui 0.6.18 → 0.6.19

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.6.19
2
+
3
+ - Add opt-in Combobox allowCustomValue input mode: preserve freely typed text on blur, Enter, and async loading or failure; only explicit option selection commits an option. Pass the selected option as the optional second onChange argument.
4
+
1
5
  # 0.6.18
2
6
 
3
7
  - Add Menu iconOnly triggers backed by the shared IconButton, preserving tooltip, focus restoration and keyboard menu interaction without a normal button border or minimum height.
package/README.md CHANGED
@@ -191,6 +191,7 @@ export function App() {
191
191
  - `TreeSelect variant="category"` 在原有树选择交互上增加图标底块、子项数量与层级连线;默认 `variant="tree"` 保留简洁样式。两种样式均支持搜索、父子联动、多选、禁用、异步加载及键盘操作。`HierarchyOption.count` 可单独提供数量。
192
192
  - `TreeTable` 复用 `Table` 的列定义,接收 `rows`、`rowKey`、`getChildren`、`rowLabel`;通过 `expanded` / `onExpandedChange` 控制展开,或使用 `defaultExpanded` / `defaultExpandAll`。`treeColumn` 默认为第一列,支持多级连线、方向键导航及独立行操作。`Column.align`、`Column.width` 可用于对齐和列宽。
193
193
  - `Combobox mode="input"` 直接在触发框输入并在下方显示候选,保留 `loadOptions`、`onCreate` 和键盘选择。输入中的文本只用于搜索;选择候选或创建成功才提交选项值,关闭时恢复已选标签。默认 `mode="panel"` 继续使用弹层内搜索。
194
+ - 需要自由文本补全时加 `allowCustomValue`:每次输入直接更新值,失焦或回车不会强制替换成候选;方向键后回车或点击仍可选择候选。`onChange(value, option?)` 在主动选择时提供对应选项,自由输入时不提供选项,可用于区分手写地点与带坐标的地点候选。
194
195
  - `MultiSelect display="tags"` 在触发框内展示可移除标签,复用 `TagInput` 的标签样式;默认 `display="summary"` 保留文字摘要。两种模式共享连续选择、搜索、数量限制和表单值。只读标签不可移除,禁用选项保持不可操作。
195
196
 
196
197
  菜单项间距统一为 `--menu-item-spacing: 1px`,菜单快捷键为靠右的纯文字提示,不预留空的指示器位置。Desktop 与 Web 共用示例:`/pickers?view=hierarchy`、`/forms?view=advanced`、`/data?view=hierarchy`;层级表格中的增删改仅更新示例内存数据。以上扩展从 0.2.0 起提供。
@@ -2,12 +2,14 @@ import { type FieldOptions } from "./field";
2
2
  import type { SelectOption } from "./types";
3
3
  export type ComboboxProps = FieldOptions & {
4
4
  value: string;
5
- onChange(value: string): void;
5
+ onChange(value: string, option?: SelectOption): void;
6
6
  options?: SelectOption[];
7
7
  loadOptions?(query: string, signal: AbortSignal): Promise<SelectOption[]>;
8
8
  onCreate?(label: string): string | void | Promise<string | void>;
9
9
  label?: string;
10
10
  placeholder?: string;
11
11
  mode?: "panel" | "input";
12
+ /** In input mode, keep typed text as the value without requiring a choice. */
13
+ allowCustomValue?: boolean;
12
14
  };
13
- export declare function Combobox({ value, onChange, options, loadOptions, onCreate, label, placeholder, mode, ...props }: ComboboxProps): import("react").JSX.Element;
15
+ export declare function Combobox({ value, onChange, options, loadOptions, onCreate, label, placeholder, mode, allowCustomValue, ...props }: ComboboxProps): import("react").JSX.Element;
@@ -31,13 +31,14 @@ function Combobox({
31
31
  label = "\u641C\u7D22\u9009\u62E9",
32
32
  placeholder = "\u8BF7\u9009\u62E9",
33
33
  mode = "panel",
34
+ allowCustomValue = false,
34
35
  ...props
35
36
  }) {
36
37
  const field = useFieldControl({ ...props, label }), anchor = useRef(null), list = useRef(null), id = useId();
37
38
  const [open, setOpen] = useState(false), [query, setQuery] = useState(""), [editing, setEditing] = useState(false), [remote, setRemote] = useState([]), [loading, setLoading] = useState(false), [error, setError] = useState(""), [failure, setFailure] = useState("load"), [active, setActive] = useState(-1), [created, setCreated] = useState(), [chosen, setChosen] = useState(), [creating, setCreating] = useState(false), [retry, setRetry] = useState(0);
38
39
  const generation = useRef(0), restoring = useRef(false), loader = useRef(loadOptions);
39
40
  loader.current = loadOptions;
40
- const inline = mode === "input", async = !!loadOptions;
41
+ const inline = mode === "input", freeText = inline && allowCustomValue, async = !!loadOptions;
41
42
  const close = useCallback(() => {
42
43
  generation.current++;
43
44
  setOpen(false);
@@ -95,7 +96,7 @@ function Combobox({
95
96
  const choose = (item) => {
96
97
  if (item.disabled || field.disabled || field.readOnly) return;
97
98
  setChosen(item);
98
- onChange(item.value);
99
+ onChange(item.value, item);
99
100
  close();
100
101
  anchor.current?.focus();
101
102
  };
@@ -114,6 +115,7 @@ function Combobox({
114
115
  generation.current++;
115
116
  setLoading(async);
116
117
  setQuery(text);
118
+ if (freeText) onChange(text);
117
119
  setEditing(true);
118
120
  setActive(inline ? -1 : 0);
119
121
  setError("");
@@ -122,7 +124,7 @@ function Combobox({
122
124
  useEffect(() => {
123
125
  list.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
124
126
  }, [activeIndex, query, loading]);
125
- const canCreate = !!onCreate && !!query.trim() && !filtered.some(
127
+ const canCreate = !freeText && !!onCreate && !!query.trim() && !filtered.some(
126
128
  (item) => item.label.toLowerCase() === query.trim().toLowerCase()
127
129
  );
128
130
  const create = async () => {
@@ -171,6 +173,10 @@ function Combobox({
171
173
  }
172
174
  } else if (event.key === "Enter" && open) {
173
175
  event.preventDefault();
176
+ if (freeText && activeIndex < 0) {
177
+ close();
178
+ return;
179
+ }
174
180
  if (!loading && !creating && !error) {
175
181
  const item = filtered[activeIndex < 0 ? first : activeIndex];
176
182
  if (item) choose(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.18",
3
+ "version": "0.6.19",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [