@gridui/tag-input 1.0.8 → 1.1.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/README.md +19 -0
- package/dist/index.js +85 -53
- package/dist/index.js.map +2 -2
- package/dist/styles.css +18 -5
- package/dist/tag-input/tag-input.d.ts +6 -0
- package/docs/catalog.json +7 -2
- package/docs/reference/README.md +4 -0
- package/docs/reference/tag-input.md +135 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -16,3 +16,22 @@ Input supplies the control surface, Button supplies tag actions, and Form hides
|
|
|
16
16
|
Applications own routes, labels, state persistence, and branding.
|
|
17
17
|
|
|
18
18
|
See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md) and [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-core/tag-input/.changeset/history).
|
|
19
|
+
|
|
20
|
+
[Component reference](docs/reference/README.md) contains focused API pages for each public component.
|
|
21
|
+
|
|
22
|
+
## Drafts and suggestions
|
|
23
|
+
|
|
24
|
+
`draft`/`onDraftChange` control the text being edited independently of committed
|
|
25
|
+
value/onValueChange. Omit draft for local text, optionally initialized with
|
|
26
|
+
defaultDraft. Reset requests the initial draft; controlled consumers can reject
|
|
27
|
+
that request. Draft text is excluded from native form submission.
|
|
28
|
+
|
|
29
|
+
Optional `suggestions` accepts Autocomplete options, searchLabel, emptyLabel,
|
|
30
|
+
filterOptions, loading/error labels and portalContainer. Load Overlay and Select
|
|
31
|
+
styles as well as the existing family styles when using suggestions. Selecting a
|
|
32
|
+
suggestion commits its value through normal tag validation, deduplication and
|
|
33
|
+
limits. Unknown text still commits with Enter/comma. Highlighting a suggestion
|
|
34
|
+
with arrows makes Enter choose it; IME confirmation never commits. onReject keeps
|
|
35
|
+
invalid or limited candidates editable. Use onDraftChange to drive remote options.
|
|
36
|
+
`controlSize` selects standard or small density. Native props/ref target the draft
|
|
37
|
+
input; className continues to target the encompassing tag surface.
|
package/dist/index.js
CHANGED
|
@@ -35,9 +35,10 @@ import { Button } from "@gridui/button";
|
|
|
35
35
|
import { ListFieldControl, useListField } from "@gridui/form";
|
|
36
36
|
import { controlVariants } from "@gridui/input";
|
|
37
37
|
import { isComposingKeyEvent } from "@gridui/interaction";
|
|
38
|
+
import { Autocomplete } from "@gridui/select";
|
|
38
39
|
import { cn } from "@gridui/style-utils";
|
|
39
40
|
import { X } from "lucide-react";
|
|
40
|
-
import { useState } from "react";
|
|
41
|
+
import { useRef, useState } from "react";
|
|
41
42
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
42
43
|
var TagInput = (props) => {
|
|
43
44
|
const {
|
|
@@ -58,15 +59,28 @@ var TagInput = (props) => {
|
|
|
58
59
|
readOnly,
|
|
59
60
|
onKeyDown,
|
|
60
61
|
onPaste,
|
|
62
|
+
controlSize = "standard",
|
|
63
|
+
draft: controlledDraft,
|
|
64
|
+
defaultDraft = "",
|
|
65
|
+
onDraftChange,
|
|
66
|
+
suggestions,
|
|
61
67
|
...restProps
|
|
62
68
|
} = props;
|
|
63
69
|
if (maxTags !== Infinity && (!Number.isSafeInteger(maxTags) || maxTags < 1)) {
|
|
64
70
|
throw new RangeError("TagInput maxTags must be a positive integer.");
|
|
65
71
|
}
|
|
66
72
|
const [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
] = useState(
|
|
73
|
+
localDraft,
|
|
74
|
+
setLocalDraft
|
|
75
|
+
] = useState(defaultDraft);
|
|
76
|
+
const initialDraft = useRef(defaultDraft);
|
|
77
|
+
const draft = controlledDraft ?? localDraft;
|
|
78
|
+
const setDraft = (next) => {
|
|
79
|
+
if (controlledDraft === void 0) {
|
|
80
|
+
setLocalDraft(next);
|
|
81
|
+
}
|
|
82
|
+
onDraftChange?.(next);
|
|
83
|
+
};
|
|
70
84
|
const { selected, native, control, change, available } = useListField({
|
|
71
85
|
value,
|
|
72
86
|
defaultValue,
|
|
@@ -75,7 +89,7 @@ var TagInput = (props) => {
|
|
|
75
89
|
readOnly,
|
|
76
90
|
form
|
|
77
91
|
}, () => {
|
|
78
|
-
setDraft(
|
|
92
|
+
setDraft(initialDraft.current);
|
|
79
93
|
});
|
|
80
94
|
const add = (candidates) => {
|
|
81
95
|
if (!available()) {
|
|
@@ -101,13 +115,64 @@ var TagInput = (props) => {
|
|
|
101
115
|
}));
|
|
102
116
|
control.current?.focus();
|
|
103
117
|
};
|
|
118
|
+
const inputProps = {
|
|
119
|
+
...restProps,
|
|
120
|
+
form,
|
|
121
|
+
disabled,
|
|
122
|
+
readOnly,
|
|
123
|
+
value: draft,
|
|
124
|
+
"aria-required": required,
|
|
125
|
+
ref: (element) => {
|
|
126
|
+
control.current = element;
|
|
127
|
+
if (typeof ref === "function") {
|
|
128
|
+
return ref(element);
|
|
129
|
+
}
|
|
130
|
+
if (ref) {
|
|
131
|
+
ref.current = element;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
className: cn("gridui-tag-input-editor gridui-u-tag-input--min-w-24 gridui-u-tag-input--w-full gridui-u-tag-input--min-h-0 gridui-u-tag-input--flex-1 gridui-u-tag-input--border-0 gridui-u-tag-input--bg-transparent gridui-u-tag-input--p-0 gridui-u-tag-input--text-foreground gridui-u-tag-input--type-input gridui-u-tag-input--outline-none"),
|
|
135
|
+
onChange: (event) => {
|
|
136
|
+
setDraft(event.currentTarget.value);
|
|
137
|
+
},
|
|
138
|
+
onKeyDown: (event) => {
|
|
139
|
+
onKeyDown?.(event);
|
|
140
|
+
if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || !available()) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (event.key === "Enter" && event.currentTarget.getAttribute("aria-expanded") === "true" && event.currentTarget.getAttribute("aria-activedescendant")) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if ((event.key === "Enter" || event.key === ",") && draft.trim()) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
add([draft]);
|
|
149
|
+
}
|
|
150
|
+
if (event.key === "Backspace" && !draft && selected.length) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
const buttons = event.currentTarget.closest(".gridui-tag-input")?.querySelectorAll("[data-tag-remove]");
|
|
153
|
+
buttons?.item(buttons.length - 1).focus();
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
onPaste: (event) => {
|
|
157
|
+
onPaste?.(event);
|
|
158
|
+
if (event.defaultPrevented || !available()) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const text = event.clipboardData.getData("text");
|
|
162
|
+
if (/[\n,]/.test(text)) {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
const input = event.currentTarget;
|
|
165
|
+
add(`${draft.slice(0, input.selectionStart ?? draft.length)}${text}${draft.slice(input.selectionEnd ?? draft.length)}`.split(/[\n,]/));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
104
169
|
return /* @__PURE__ */ jsxs(
|
|
105
170
|
"div",
|
|
106
171
|
{
|
|
107
172
|
dir: restProps.dir,
|
|
108
173
|
"data-gridui-outline-target": "",
|
|
109
174
|
"aria-invalid": restProps["aria-invalid"],
|
|
110
|
-
className: cn(controlVariants(), "gridui-tag-input gridui-u-tag-input--flex gridui-u-tag-input--flex-wrap gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--has-[input:disabled]:opacity-50", className),
|
|
175
|
+
className: cn(controlVariants({ size: controlSize }), "gridui-tag-input gridui-u-tag-input--flex gridui-u-tag-input--flex-wrap gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--has-[input:disabled]:opacity-50", className),
|
|
111
176
|
children: [
|
|
112
177
|
/* @__PURE__ */ jsx(
|
|
113
178
|
"ul",
|
|
@@ -160,57 +225,24 @@ var TagInput = (props) => {
|
|
|
160
225
|
})
|
|
161
226
|
}
|
|
162
227
|
),
|
|
163
|
-
/* @__PURE__ */ jsx(
|
|
164
|
-
|
|
228
|
+
suggestions ? /* @__PURE__ */ jsx(
|
|
229
|
+
Autocomplete,
|
|
165
230
|
{
|
|
166
|
-
...
|
|
167
|
-
|
|
168
|
-
control.current = element;
|
|
169
|
-
if (typeof ref === "function") {
|
|
170
|
-
return ref(element);
|
|
171
|
-
}
|
|
172
|
-
if (ref) {
|
|
173
|
-
ref.current = element;
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
type: "text",
|
|
177
|
-
form,
|
|
178
|
-
disabled,
|
|
179
|
-
readOnly,
|
|
231
|
+
...inputProps,
|
|
232
|
+
...suggestions,
|
|
180
233
|
value: draft,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
},
|
|
186
|
-
onKeyDown: (event) => {
|
|
187
|
-
onKeyDown?.(event);
|
|
188
|
-
if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || !available()) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
if ((event.key === "Enter" || event.key === ",") && draft.trim()) {
|
|
192
|
-
event.preventDefault();
|
|
193
|
-
add([draft]);
|
|
194
|
-
}
|
|
195
|
-
if (event.key === "Backspace" && !draft && selected.length) {
|
|
196
|
-
event.preventDefault();
|
|
197
|
-
const buttons = event.currentTarget.parentElement?.querySelectorAll("[data-tag-remove]");
|
|
198
|
-
buttons?.item(buttons.length - 1).focus();
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
onPaste: (event) => {
|
|
202
|
-
onPaste?.(event);
|
|
203
|
-
if (event.defaultPrevented || !available()) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const text = event.clipboardData.getData("text");
|
|
207
|
-
if (/[\n,]/.test(text)) {
|
|
208
|
-
event.preventDefault();
|
|
209
|
-
const input = event.currentTarget;
|
|
210
|
-
add(`${draft.slice(0, input.selectionStart ?? draft.length)}${text}${draft.slice(input.selectionEnd ?? draft.length)}`.split(/[\n,]/));
|
|
211
|
-
}
|
|
234
|
+
controlSize,
|
|
235
|
+
rootClassName: cn("gridui-tag-input-suggestions gridui-u-tag-input--min-w-24 gridui-u-tag-input--w-0 gridui-u-tag-input--flex-1"),
|
|
236
|
+
onOptionSelect: (option) => {
|
|
237
|
+
add([option.value]);
|
|
212
238
|
}
|
|
213
239
|
}
|
|
240
|
+
) : /* @__PURE__ */ jsx(
|
|
241
|
+
"input",
|
|
242
|
+
{
|
|
243
|
+
...inputProps,
|
|
244
|
+
type: "text"
|
|
245
|
+
}
|
|
214
246
|
),
|
|
215
247
|
/* @__PURE__ */ jsx(
|
|
216
248
|
ListFieldControl,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/tag-input/model.ts", "../src/tag-input/tag-input.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * @author WMXPY\n * @package Tag Input\n * @namespace TagInput\n * @description Model\n */\n\nexport type TagRejectionReason = \"duplicate\" | \"limit\" | \"invalid\";\n\nexport type TagRejection = {\n readonly value: string;\n readonly reason: TagRejectionReason;\n};\n\nexport const appendTags = (\n current: readonly string[], candidates: readonly string[], maxTags: number,\n validate?: (value: string) => boolean,\n): {\n values: string[];\n rejected: TagRejection[];\n} => {\n const values = [...current];\n const rejected: TagRejection[] = [];\n for (const candidate of candidates) {\n const value = candidate.trim();\n if (!value) {\n continue;\n }\n let reason: TagRejectionReason | undefined;\n if (values.includes(value)) {\n reason = \"duplicate\";\n }\n else if (validate && !validate(value)) {\n reason = \"invalid\";\n }\n else if (values.length >= maxTags) {\n reason = \"limit\";\n }\n if (reason) {\n rejected.push({\n value,\n reason,\n });\n } else {\n values.push(value);\n }\n }\n return {\n values,\n rejected,\n };\n};\n", "/**\n * @author WMXPY\n * @package Tag Input\n * @namespace TagInput\n * @description Tag Input\n */\n\nimport { appendTags, type TagRejection } from \"./model\";\nimport { Button } from \"@gridui/button\";\nimport { ListFieldControl, type ListFieldProps, useListField } from \"@gridui/form\";\nimport { controlVariants } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { cn } from \"@gridui/style-utils\";\nimport { X } from \"lucide-react\";\nimport { type ComponentPropsWithRef, type FC, useState } from \"react\";\n\nexport type TagInputProps = Omit<ComponentPropsWithRef<\"input\">, \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"size\"> & ListFieldProps & {\n readonly listLabel: string;\n readonly removeLabel: (tag: string) => string;\n readonly maxTags?: number;\n readonly validateTag?: (tag: string) => boolean;\n readonly onReject?: (rejection: TagRejection) => void;\n};\n\nexport const TagInput: FC<TagInputProps> = (props: TagInputProps) => {\n const { value, defaultValue, onValueChange, listLabel, removeLabel, maxTags = Infinity, validateTag, onReject,\n className, ref, name, required, form, disabled, readOnly, onKeyDown, onPaste, ...restProps } = props;\n if (maxTags !== Infinity && (!Number.isSafeInteger(maxTags) || maxTags < 1)) {\n throw new RangeError(\"TagInput maxTags must be a positive integer.\");\n }\n const [\n draft,\n setDraft,\n ] = useState(\"\");\n const { selected, native, control, change, available } = useListField({\n value,\n defaultValue,\n onValueChange,\n disabled,\n readOnly,\n form,\n }, () => {\n setDraft(\"\");\n });\n const add = (candidates: string[]) => {\n if (!available()) {\n return;\n }\n const result = appendTags(selected, candidates, maxTags, validateTag);\n change(result.values);\n result.rejected.forEach(rejection => {\n onReject?.(rejection);\n });\n setDraft(result.rejected.filter(rejection => {\n return rejection.reason !== \"duplicate\";\n }).map(rejection => {\n return rejection.value;\n })\n .join(\", \"));\n };\n const remove = (tag: string) => {\n if (!available()) {\n return;\n }\n change(selected.filter(entry => {\n return entry !== tag;\n }));\n control.current?.focus();\n };\n return (<div\n dir={restProps.dir}\n data-gridui-outline-target=\"\"\n aria-invalid={restProps[\"aria-invalid\"]}\n className={cn(controlVariants(), \"gridui-tag-input gridui-u-tag-input--flex gridui-u-tag-input--flex-wrap gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--has-[input:disabled]:opacity-50\", className)}\n >\n <ul\n aria-label={listLabel}\n className=\"gridui-u-tag-input--contents gridui-u-tag-input--list-none\"\n >\n {selected.map(tag => {\n return (<li\n key={tag}\n className=\"gridui-u-tag-input--inline-flex gridui-u-tag-input--max-w-full gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--border gridui-u-tag-input--border-border gridui-u-tag-input--bg-surface gridui-u-tag-input--ps-gridui-8\"\n >\n <span\n className=\"gridui-u-tag-input--min-w-0 gridui-u-tag-input--wrap-anywhere\"\n >\n {tag}\n </span>\n <Button\n variant=\"quiet\"\n layout=\"icon\"\n size=\"small\"\n aria-label={removeLabel(tag)}\n disabled={disabled || readOnly}\n data-tag-remove=\"\"\n onClick={() => {\n remove(tag);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Backspace\" || event.key === \"Delete\") {\n event.preventDefault(); remove(tag);\n }\n }}\n >\n <X\n aria-hidden=\"true\"\n />\n </Button>\n </li>);\n })}\n </ul>\n <input\n {...restProps}\n ref={(element) => {\n control.current = element;\n if (typeof ref === \"function\") {\n return ref(element);\n }\n if (ref) {\n ref.current = element;\n }\n }}\n type=\"text\"\n form={form}\n disabled={disabled}\n readOnly={readOnly}\n value={draft}\n aria-required={required}\n className=\"gridui-u-tag-input--min-w-24 gridui-u-tag-input--flex-1 gridui-u-tag-input--border-0 gridui-u-tag-input--bg-transparent gridui-u-tag-input--text-foreground gridui-u-tag-input--type-input\"\n onChange={(event) => {\n setDraft(event.target.value);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || !available()) {\n return;\n }\n if ((event.key === \"Enter\" || event.key === \",\") && draft.trim()) {\n event.preventDefault(); add([draft]);\n }\n if (event.key === \"Backspace\" && !draft && selected.length) {\n event.preventDefault();\n const buttons = event.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>(\"[data-tag-remove]\");\n buttons?.item(buttons.length - 1).focus();\n }\n }}\n onPaste={(event) => {\n onPaste?.(event);\n if (event.defaultPrevented || !available()) {\n return;\n }\n const text = event.clipboardData.getData(\"text\");\n if (/[\\n,]/.test(text)) {\n event.preventDefault(); const input = event.currentTarget;\n add(`${draft.slice(0, input.selectionStart ?? draft.length)}${text}${draft.slice(input.selectionEnd ?? draft.length)}`.split(/[\\n,]/));\n }\n }}\n />\n <ListFieldControl\n ref={native}\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n value={selected}\n onInvalidFocus={() => {\n control.current?.focus();\n }}\n >\n {selected.map(tag => {\n return (<option\n key={tag}\n value={tag}\n >\n {tag}\n </option>);\n })}\n </ListFieldControl>\n </div>);\n};\n"],
|
|
5
|
-
"mappings": ";AAcO,IAAM,aAAa,CACtB,SAA4B,YAA+B,SAC3D,aAIC;AACD,QAAM,SAAS,CAAC,GAAG,OAAO;AAC1B,QAAM,WAA2B,CAAC;AAClC,aAAW,aAAa,YAAY;AAChC,UAAM,QAAQ,UAAU,KAAK;AAC7B,QAAI,CAAC,OAAO;AACR;AAAA,IACJ;AACA,QAAI;AACJ,QAAI,OAAO,SAAS,KAAK,GAAG;AACxB,eAAS;AAAA,IACb,WACS,YAAY,CAAC,SAAS,KAAK,GAAG;AACnC,eAAS;AAAA,IACb,WACS,OAAO,UAAU,SAAS;AAC/B,eAAS;AAAA,IACb;AACA,QAAI,QAAQ;AACR,eAAS,KAAK;AAAA,QACV;AAAA,QACA;AAAA,MACJ,CAAC;AAAA,IACL,OAAO;AACH,aAAO,KAAK,KAAK;AAAA,IACrB;AAAA,EACJ;AACA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,EACJ;AACJ;;;AC3CA,SAAS,cAAc;AACvB,SAAS,kBAAuC,oBAAoB;AACpE,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,UAAU;AACnB,SAAS,SAAS;AAClB,SAA8C,gBAAgB;
|
|
4
|
+
"sourcesContent": ["/**\n * @author WMXPY\n * @package Tag Input\n * @namespace TagInput\n * @description Model\n */\n\nexport type TagRejectionReason = \"duplicate\" | \"limit\" | \"invalid\";\n\nexport type TagRejection = {\n readonly value: string;\n readonly reason: TagRejectionReason;\n};\n\nexport const appendTags = (\n current: readonly string[], candidates: readonly string[], maxTags: number,\n validate?: (value: string) => boolean,\n): {\n values: string[];\n rejected: TagRejection[];\n} => {\n const values = [...current];\n const rejected: TagRejection[] = [];\n for (const candidate of candidates) {\n const value = candidate.trim();\n if (!value) {\n continue;\n }\n let reason: TagRejectionReason | undefined;\n if (values.includes(value)) {\n reason = \"duplicate\";\n }\n else if (validate && !validate(value)) {\n reason = \"invalid\";\n }\n else if (values.length >= maxTags) {\n reason = \"limit\";\n }\n if (reason) {\n rejected.push({\n value,\n reason,\n });\n } else {\n values.push(value);\n }\n }\n return {\n values,\n rejected,\n };\n};\n", "/**\n * @author WMXPY\n * @package Tag Input\n * @namespace TagInput\n * @description Tag Input\n */\n\nimport { appendTags, type TagRejection } from \"./model\";\nimport { Button } from \"@gridui/button\";\nimport { ListFieldControl, type ListFieldProps, useListField } from \"@gridui/form\";\nimport { controlVariants } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { Autocomplete, type AutocompleteProps } from \"@gridui/select\";\nimport { cn } from \"@gridui/style-utils\";\nimport { X } from \"lucide-react\";\nimport { type ComponentPropsWithRef, type FC, useRef, useState } from \"react\";\n\nexport type TagInputProps = Omit<ComponentPropsWithRef<\"input\">, \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"size\"> & ListFieldProps & {\n readonly listLabel: string;\n readonly removeLabel: (tag: string) => string;\n readonly maxTags?: number;\n readonly controlSize?: \"standard\" | \"small\";\n readonly draft?: string;\n readonly defaultDraft?: string;\n readonly onDraftChange?: (value: string) => void;\n readonly suggestions?: Pick<AutocompleteProps, \"options\" | \"searchLabel\" | \"emptyLabel\" | \"loading\" | \"loadingLabel\" | \"errorLabel\" | \"resultCountLabel\" | \"filterOptions\" | \"portalContainer\">;\n readonly validateTag?: (tag: string) => boolean;\n readonly onReject?: (rejection: TagRejection) => void;\n};\n\nexport const TagInput: FC<TagInputProps> = (props: TagInputProps) => {\n const { value, defaultValue, onValueChange, listLabel, removeLabel, maxTags = Infinity, validateTag, onReject,\n className, ref, name, required, form, disabled, readOnly, onKeyDown, onPaste, controlSize = \"standard\",\n draft: controlledDraft, defaultDraft = \"\", onDraftChange, suggestions, ...restProps } = props;\n if (maxTags !== Infinity && (!Number.isSafeInteger(maxTags) || maxTags < 1)) {\n throw new RangeError(\"TagInput maxTags must be a positive integer.\");\n }\n const [\n localDraft,\n setLocalDraft,\n ] = useState(defaultDraft);\n const initialDraft = useRef(defaultDraft);\n const draft = controlledDraft ?? localDraft;\n const setDraft = (next: string) => {\n if (controlledDraft === undefined) {\n setLocalDraft(next);\n }\n onDraftChange?.(next);\n };\n const { selected, native, control, change, available } = useListField({\n value,\n defaultValue,\n onValueChange,\n disabled,\n readOnly,\n form,\n }, () => {\n setDraft(initialDraft.current);\n });\n const add = (candidates: string[]) => {\n if (!available()) {\n return;\n }\n const result = appendTags(selected, candidates, maxTags, validateTag);\n change(result.values);\n result.rejected.forEach(rejection => {\n onReject?.(rejection);\n });\n setDraft(result.rejected.filter(rejection => {\n return rejection.reason !== \"duplicate\";\n }).map(rejection => {\n return rejection.value;\n })\n .join(\", \"));\n };\n const remove = (tag: string) => {\n if (!available()) {\n return;\n }\n change(selected.filter(entry => {\n return entry !== tag;\n }));\n control.current?.focus();\n };\n const inputProps: Omit<ComponentPropsWithRef<\"input\">, \"value\" | \"defaultValue\" | \"type\"> & {\n value: string;\n } = {\n ...restProps,\n form,\n disabled,\n readOnly,\n value: draft,\n \"aria-required\": required,\n ref: (element) => {\n control.current = element;\n if (typeof ref === \"function\") {\n return ref(element);\n }\n if (ref) {\n ref.current = element;\n }\n },\n className: cn(\"gridui-tag-input-editor gridui-u-tag-input--min-w-24 gridui-u-tag-input--w-full gridui-u-tag-input--min-h-0 gridui-u-tag-input--flex-1 gridui-u-tag-input--border-0 gridui-u-tag-input--bg-transparent gridui-u-tag-input--p-0 gridui-u-tag-input--text-foreground gridui-u-tag-input--type-input gridui-u-tag-input--outline-none\"),\n onChange: (event) => {\n setDraft(event.currentTarget.value);\n },\n onKeyDown: (event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || !available()) {\n return;\n }\n if (event.key === \"Enter\" && event.currentTarget.getAttribute(\"aria-expanded\") === \"true\"\n && event.currentTarget.getAttribute(\"aria-activedescendant\")) {\n return;\n }\n if ((event.key === \"Enter\" || event.key === \",\") && draft.trim()) {\n event.preventDefault(); add([draft]);\n }\n if (event.key === \"Backspace\" && !draft && selected.length) {\n event.preventDefault();\n const buttons = event.currentTarget.closest(\".gridui-tag-input\")?.querySelectorAll<HTMLButtonElement>(\"[data-tag-remove]\");\n buttons?.item(buttons.length - 1).focus();\n }\n },\n onPaste: (event) => {\n onPaste?.(event);\n if (event.defaultPrevented || !available()) {\n return;\n }\n const text = event.clipboardData.getData(\"text\");\n if (/[\\n,]/.test(text)) {\n event.preventDefault();\n const input = event.currentTarget;\n add(`${draft.slice(0, input.selectionStart ?? draft.length)}${text}${draft.slice(input.selectionEnd ?? draft.length)}`.split(/[\\n,]/));\n }\n },\n };\n return (<div\n dir={restProps.dir}\n data-gridui-outline-target=\"\"\n aria-invalid={restProps[\"aria-invalid\"]}\n className={cn(controlVariants({ size: controlSize }), \"gridui-tag-input gridui-u-tag-input--flex gridui-u-tag-input--flex-wrap gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--has-[input:disabled]:opacity-50\", className)}\n >\n <ul\n aria-label={listLabel}\n className=\"gridui-u-tag-input--contents gridui-u-tag-input--list-none\"\n >\n {selected.map(tag => {\n return (<li\n key={tag}\n className=\"gridui-u-tag-input--inline-flex gridui-u-tag-input--max-w-full gridui-u-tag-input--items-center gridui-u-tag-input--gap-gridui-4 gridui-u-tag-input--border gridui-u-tag-input--border-border gridui-u-tag-input--bg-surface gridui-u-tag-input--ps-gridui-8\"\n >\n <span\n className=\"gridui-u-tag-input--min-w-0 gridui-u-tag-input--wrap-anywhere\"\n >\n {tag}\n </span>\n <Button\n variant=\"quiet\"\n layout=\"icon\"\n size=\"small\"\n aria-label={removeLabel(tag)}\n disabled={disabled || readOnly}\n data-tag-remove=\"\"\n onClick={() => {\n remove(tag);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Backspace\" || event.key === \"Delete\") {\n event.preventDefault(); remove(tag);\n }\n }}\n >\n <X\n aria-hidden=\"true\"\n />\n </Button>\n </li>);\n })}\n </ul>\n {suggestions ? (<Autocomplete\n {...inputProps}\n {...suggestions}\n value={draft}\n controlSize={controlSize}\n rootClassName={cn(\"gridui-tag-input-suggestions gridui-u-tag-input--min-w-24 gridui-u-tag-input--w-0 gridui-u-tag-input--flex-1\")}\n onOptionSelect={(option) => {\n add([option.value]);\n }}\n />)\n : (<input\n {...inputProps}\n type=\"text\"\n />)}\n <ListFieldControl\n ref={native}\n name={name}\n form={form}\n required={required}\n disabled={disabled}\n value={selected}\n onInvalidFocus={() => {\n control.current?.focus();\n }}\n >\n {selected.map(tag => {\n return (<option\n key={tag}\n value={tag}\n >\n {tag}\n </option>);\n })}\n </ListFieldControl>\n </div>);\n};\n"],
|
|
5
|
+
"mappings": ";AAcO,IAAM,aAAa,CACtB,SAA4B,YAA+B,SAC3D,aAIC;AACD,QAAM,SAAS,CAAC,GAAG,OAAO;AAC1B,QAAM,WAA2B,CAAC;AAClC,aAAW,aAAa,YAAY;AAChC,UAAM,QAAQ,UAAU,KAAK;AAC7B,QAAI,CAAC,OAAO;AACR;AAAA,IACJ;AACA,QAAI;AACJ,QAAI,OAAO,SAAS,KAAK,GAAG;AACxB,eAAS;AAAA,IACb,WACS,YAAY,CAAC,SAAS,KAAK,GAAG;AACnC,eAAS;AAAA,IACb,WACS,OAAO,UAAU,SAAS;AAC/B,eAAS;AAAA,IACb;AACA,QAAI,QAAQ;AACR,eAAS,KAAK;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CHANGED
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
.gridui-u-tag-input--inline-flex {
|
|
17
17
|
display: inline-flex;
|
|
18
18
|
}
|
|
19
|
+
.gridui-u-tag-input--min-h-0 {
|
|
20
|
+
min-height: 0px;
|
|
21
|
+
}
|
|
22
|
+
.gridui-u-tag-input--w-0 {
|
|
23
|
+
width: 0px;
|
|
24
|
+
}
|
|
25
|
+
.gridui-u-tag-input--w-full {
|
|
26
|
+
width: 100%;
|
|
27
|
+
}
|
|
19
28
|
.gridui-u-tag-input--max-w-full {
|
|
20
29
|
max-width: 100%;
|
|
21
30
|
}
|
|
@@ -57,6 +66,9 @@
|
|
|
57
66
|
.gridui-u-tag-input--bg-transparent {
|
|
58
67
|
background-color: transparent;
|
|
59
68
|
}
|
|
69
|
+
.gridui-u-tag-input--p-0 {
|
|
70
|
+
padding: 0px;
|
|
71
|
+
}
|
|
60
72
|
.gridui-u-tag-input--ps-gridui-8 {
|
|
61
73
|
padding-inline-start: var(--gridui-space-8);
|
|
62
74
|
}
|
|
@@ -70,6 +82,10 @@
|
|
|
70
82
|
.gridui-u-tag-input--text-foreground {
|
|
71
83
|
color: var(--gridui-foreground);
|
|
72
84
|
}
|
|
85
|
+
.gridui-u-tag-input--outline-none {
|
|
86
|
+
--tw-outline-style: none;
|
|
87
|
+
outline-style: none;
|
|
88
|
+
}
|
|
73
89
|
.gridui-u-tag-input--has-\[input\:disabled\]\:opacity-50:has(:is(input:disabled)) {
|
|
74
90
|
opacity: 50%;
|
|
75
91
|
}
|
|
@@ -77,13 +93,13 @@
|
|
|
77
93
|
@layer components {
|
|
78
94
|
.gridui-tag-input {
|
|
79
95
|
position: relative;
|
|
80
|
-
&:has(
|
|
96
|
+
&:has(input:focus-visible) {
|
|
81
97
|
z-index: var(--gridui-z-interaction);
|
|
82
98
|
outline: var(--gridui-focus-width) solid var(--gridui-focus-color);
|
|
83
99
|
outline-offset: var(--gridui-focus-offset);
|
|
84
100
|
}
|
|
85
101
|
@media (hover: hover) and (pointer: fine) {
|
|
86
|
-
&:has(
|
|
102
|
+
&:has(input:hover:not(:disabled, [readonly])):not(:has(:focus-visible)) {
|
|
87
103
|
z-index: var(--gridui-z-boundary);
|
|
88
104
|
outline: var(--gridui-hover-width) solid var(--gridui-focus-color);
|
|
89
105
|
@supports (color: color-mix(in lab, red, red)) {
|
|
@@ -92,9 +108,6 @@
|
|
|
92
108
|
outline-offset: var(--gridui-hover-offset);
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
|
-
> input {
|
|
96
|
-
outline: none;
|
|
97
|
-
}
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
@property --tw-border-style {
|
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type TagRejection } from "./model";
|
|
8
8
|
import { type ListFieldProps } from "@gridui/form";
|
|
9
|
+
import { type AutocompleteProps } from "@gridui/select";
|
|
9
10
|
import { type ComponentPropsWithRef, type FC } from "react";
|
|
10
11
|
export type TagInputProps = Omit<ComponentPropsWithRef<"input">, "value" | "defaultValue" | "onChange" | "type" | "size"> & ListFieldProps & {
|
|
11
12
|
readonly listLabel: string;
|
|
12
13
|
readonly removeLabel: (tag: string) => string;
|
|
13
14
|
readonly maxTags?: number;
|
|
15
|
+
readonly controlSize?: "standard" | "small";
|
|
16
|
+
readonly draft?: string;
|
|
17
|
+
readonly defaultDraft?: string;
|
|
18
|
+
readonly onDraftChange?: (value: string) => void;
|
|
19
|
+
readonly suggestions?: Pick<AutocompleteProps, "options" | "searchLabel" | "emptyLabel" | "loading" | "loadingLabel" | "errorLabel" | "resultCountLabel" | "filterOptions" | "portalContainer">;
|
|
14
20
|
readonly validateTag?: (tag: string) => boolean;
|
|
15
21
|
readonly onReject?: (rejection: TagRejection) => void;
|
|
16
22
|
};
|
package/docs/catalog.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "@gridui/tag-input",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"category": "core",
|
|
6
6
|
"description": "GridUI React tag input",
|
|
7
7
|
"usage": "Input supplies the control surface, Button supplies tag actions, and Form hides the native multiple-value bridge. Applications own routes, labels, state persistence, and branding.",
|
|
8
8
|
"documentation": [
|
|
9
|
-
"README.md"
|
|
9
|
+
"README.md",
|
|
10
|
+
"docs/reference/README.md",
|
|
11
|
+
"docs/reference/tag-input.md"
|
|
10
12
|
],
|
|
11
13
|
"exports": [
|
|
12
14
|
{
|
|
@@ -36,9 +38,12 @@
|
|
|
36
38
|
"@gridui/form/styles.css",
|
|
37
39
|
"@gridui/overlay/styles.css",
|
|
38
40
|
"@gridui/input/styles.css",
|
|
41
|
+
"@gridui/select/styles.css",
|
|
39
42
|
"@gridui/tag-input/styles.css"
|
|
40
43
|
],
|
|
41
44
|
"examples": [
|
|
45
|
+
"https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/tag-input/stories/editing-tags.mdx",
|
|
46
|
+
"https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/tag-input/stories/suggestions.mdx",
|
|
42
47
|
"https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/tag-input/stories/tag-input.stories.tsx"
|
|
43
48
|
]
|
|
44
49
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<!-- Generated from public Props and owned stories. Run pnpm docs:storybook. -->
|
|
2
|
+
# TagInput
|
|
3
|
+
|
|
4
|
+
Edits a list of text values as removable tags. Use it for keywords or other entries that users create directly.
|
|
5
|
+
|
|
6
|
+
Import from ``@gridui/tag-input`` and load Theme before this family's stylesheet.
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
import { TagInput } from "@gridui/tag-input";
|
|
10
|
+
import "@gridui/theme/styles.css";
|
|
11
|
+
import "@gridui/tag-input/styles.css";
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Read the [package contract](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/tag-input/README.md) for shared behavior and stylesheet dependencies.
|
|
15
|
+
|
|
16
|
+
The [working composition](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/tag-input/stories/tag-input.stories.tsx) demonstrates required context, state, and related components. Use View code in Storybook to inspect the actual implementation.
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
The public Props type is the source of these signatures. Defaults below are explicit implementation defaults; story presets are separate. Native attributes remain available through the exported Props type.
|
|
21
|
+
|
|
22
|
+
### form
|
|
23
|
+
|
|
24
|
+
``string | undefined`` · Optional
|
|
25
|
+
|
|
26
|
+
### children
|
|
27
|
+
|
|
28
|
+
``ReactNode`` · Optional
|
|
29
|
+
|
|
30
|
+
Content rendered inside the component.
|
|
31
|
+
|
|
32
|
+
### onFocus
|
|
33
|
+
|
|
34
|
+
``(event: FocusEvent<HTMLInputElement, Element>): void`` · Optional
|
|
35
|
+
|
|
36
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
37
|
+
|
|
38
|
+
### onBlur
|
|
39
|
+
|
|
40
|
+
``(event: FocusEvent<HTMLInputElement, Element>): void`` · Optional
|
|
41
|
+
|
|
42
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
43
|
+
|
|
44
|
+
### onSubmit
|
|
45
|
+
|
|
46
|
+
``(event: SubmitEvent<HTMLInputElement>): void`` · Optional
|
|
47
|
+
|
|
48
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
49
|
+
|
|
50
|
+
### onClick
|
|
51
|
+
|
|
52
|
+
``(event: MouseEvent<HTMLInputElement, MouseEvent>): void`` · Optional
|
|
53
|
+
|
|
54
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
55
|
+
|
|
56
|
+
### disabled
|
|
57
|
+
|
|
58
|
+
``boolean | undefined`` · Optional
|
|
59
|
+
|
|
60
|
+
Prevents interaction when enabled.
|
|
61
|
+
|
|
62
|
+
### readOnly
|
|
63
|
+
|
|
64
|
+
``boolean | undefined`` · Optional
|
|
65
|
+
|
|
66
|
+
Allows reading without changing the value.
|
|
67
|
+
|
|
68
|
+
### value
|
|
69
|
+
|
|
70
|
+
``readonly string[] | undefined`` · Optional
|
|
71
|
+
|
|
72
|
+
Controlled value. Pair with the corresponding change callback.
|
|
73
|
+
|
|
74
|
+
### defaultValue
|
|
75
|
+
|
|
76
|
+
``readonly string[] | undefined`` · Optional
|
|
77
|
+
|
|
78
|
+
Initial uncontrolled value. Reset the story after changing it.
|
|
79
|
+
|
|
80
|
+
### onValueChange
|
|
81
|
+
|
|
82
|
+
``(value: string[]): void`` · Optional
|
|
83
|
+
|
|
84
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
85
|
+
|
|
86
|
+
### listLabel
|
|
87
|
+
|
|
88
|
+
``string`` · Required
|
|
89
|
+
|
|
90
|
+
### removeLabel
|
|
91
|
+
|
|
92
|
+
``(tag: string) => string`` · Required
|
|
93
|
+
|
|
94
|
+
### maxTags
|
|
95
|
+
|
|
96
|
+
``number | undefined`` · Optional
|
|
97
|
+
|
|
98
|
+
Default: ``Infinity``
|
|
99
|
+
|
|
100
|
+
### controlSize
|
|
101
|
+
|
|
102
|
+
``"small" | "standard" | undefined`` · Optional
|
|
103
|
+
|
|
104
|
+
Default: ``"standard"``
|
|
105
|
+
|
|
106
|
+
### draft
|
|
107
|
+
|
|
108
|
+
``string | undefined`` · Optional
|
|
109
|
+
|
|
110
|
+
### defaultDraft
|
|
111
|
+
|
|
112
|
+
``string | undefined`` · Optional
|
|
113
|
+
|
|
114
|
+
Default: ``""``
|
|
115
|
+
|
|
116
|
+
### onDraftChange
|
|
117
|
+
|
|
118
|
+
``(value: string): void`` · Optional
|
|
119
|
+
|
|
120
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
121
|
+
|
|
122
|
+
### suggestions
|
|
123
|
+
|
|
124
|
+
``Pick<AutocompleteProps, "loading" | "filterOptions" | "loadingLabel" | "errorLabel" | "resultCountLabel" | "options" | "searchLabel" | "emptyLabel" | "portalContainer"> | undefined`` · Optional
|
|
125
|
+
|
|
126
|
+
### validateTag
|
|
127
|
+
|
|
128
|
+
``((tag: string) => boolean) | undefined`` · Optional
|
|
129
|
+
|
|
130
|
+
### onReject
|
|
131
|
+
|
|
132
|
+
``(rejection: TagRejection): void`` · Optional
|
|
133
|
+
|
|
134
|
+
Called when the corresponding interaction occurs; inspect the arguments in Actions.
|
|
135
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/tag-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "GridUI React tag input",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
"react-dom": "^19.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gridui/button": "^4.
|
|
31
|
-
"@gridui/form": "^4.
|
|
32
|
-
"@gridui/input": "^
|
|
30
|
+
"@gridui/button": "^4.1.0",
|
|
31
|
+
"@gridui/form": "^4.1.1",
|
|
32
|
+
"@gridui/input": "^3.0.1",
|
|
33
33
|
"@gridui/interaction": "^1.2.1",
|
|
34
|
-
"@gridui/
|
|
34
|
+
"@gridui/select": "^1.2.1",
|
|
35
|
+
"@gridui/style-utils": "^4.0.0",
|
|
35
36
|
"@gridui/theme": "^2.5.3",
|
|
36
37
|
"lucide-react": "1.70.0"
|
|
37
38
|
},
|