@deque/cauldron-react 5.9.1 → 5.10.0-canary.83e0212e
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.
|
@@ -3,9 +3,11 @@ import { ComboboxValue } from './ComboboxOption';
|
|
|
3
3
|
type ComboboxContext = {
|
|
4
4
|
autocomplete: 'none' | 'manual' | 'automatic';
|
|
5
5
|
inputValue: ComboboxValue;
|
|
6
|
+
formValue: ComboboxValue;
|
|
6
7
|
selectedValue: ComboboxValue;
|
|
7
8
|
matchingOptions: Map<HTMLElement, ComboboxOptionState>;
|
|
8
9
|
setMatchingOptions: React.Dispatch<React.SetStateAction<Map<HTMLElement, ComboboxOptionState>>>;
|
|
10
|
+
setFormValue: React.Dispatch<React.SetStateAction<ComboboxValue>>;
|
|
9
11
|
matches: (<T extends string = string>(value: T) => boolean) | boolean;
|
|
10
12
|
};
|
|
11
13
|
export type ComboboxOptionState = {
|
|
@@ -17,6 +19,6 @@ type ComboboxProvider = {
|
|
|
17
19
|
matches: ((inputValue: string, value: string) => boolean) | boolean;
|
|
18
20
|
} & Omit<ComboboxContext, 'matches'>;
|
|
19
21
|
declare const ComboboxContext: React.Context<ComboboxContext>;
|
|
20
|
-
declare function ComboboxProvider({ autocomplete, inputValue, selectedValue, matches, matchingOptions, setMatchingOptions, children }: ComboboxProvider): JSX.Element;
|
|
22
|
+
declare function ComboboxProvider({ autocomplete, inputValue, formValue, selectedValue, matches, matchingOptions, setMatchingOptions, setFormValue, children }: ComboboxProvider): JSX.Element;
|
|
21
23
|
declare function useComboboxContext(): ComboboxContext;
|
|
22
24
|
export { ComboboxProvider, useComboboxContext };
|
package/lib/index.js
CHANGED
|
@@ -4188,30 +4188,36 @@ ListboxGroup.displayName = 'ListboxGroup';
|
|
|
4188
4188
|
var ComboboxContext = React.createContext({
|
|
4189
4189
|
autocomplete: 'manual',
|
|
4190
4190
|
inputValue: undefined,
|
|
4191
|
+
formValue: undefined,
|
|
4191
4192
|
selectedValue: undefined,
|
|
4192
4193
|
matches: true,
|
|
4193
4194
|
matchingOptions: new Map(),
|
|
4194
|
-
setMatchingOptions: function () { return null; }
|
|
4195
|
+
setMatchingOptions: function () { return null; },
|
|
4196
|
+
setFormValue: function () { return null; }
|
|
4195
4197
|
});
|
|
4196
4198
|
function ComboboxProvider(_a) {
|
|
4197
|
-
var autocomplete = _a.autocomplete, inputValue = _a.inputValue, selectedValue = _a.selectedValue, matches = _a.matches, matchingOptions = _a.matchingOptions, setMatchingOptions = _a.setMatchingOptions, children = _a.children;
|
|
4199
|
+
var autocomplete = _a.autocomplete, inputValue = _a.inputValue, formValue = _a.formValue, selectedValue = _a.selectedValue, matches = _a.matches, matchingOptions = _a.matchingOptions, setMatchingOptions = _a.setMatchingOptions, setFormValue = _a.setFormValue, children = _a.children;
|
|
4198
4200
|
var Provider = ComboboxContext.Provider;
|
|
4199
4201
|
var contextValue = React.useMemo(function () { return ({
|
|
4200
4202
|
autocomplete: autocomplete,
|
|
4201
4203
|
inputValue: inputValue,
|
|
4204
|
+
formValue: formValue,
|
|
4202
4205
|
selectedValue: selectedValue,
|
|
4203
4206
|
matches: typeof matches === 'function' && !!inputValue
|
|
4204
4207
|
? function (value) { return matches(inputValue, value); }
|
|
4205
4208
|
: true,
|
|
4206
4209
|
matchingOptions: matchingOptions,
|
|
4207
|
-
setMatchingOptions: setMatchingOptions
|
|
4210
|
+
setMatchingOptions: setMatchingOptions,
|
|
4211
|
+
setFormValue: setFormValue
|
|
4208
4212
|
}); }, [
|
|
4209
4213
|
autocomplete,
|
|
4210
4214
|
inputValue,
|
|
4215
|
+
formValue,
|
|
4211
4216
|
selectedValue,
|
|
4212
4217
|
matches,
|
|
4213
4218
|
matchingOptions,
|
|
4214
|
-
setMatchingOptions
|
|
4219
|
+
setMatchingOptions,
|
|
4220
|
+
setFormValue
|
|
4215
4221
|
]);
|
|
4216
4222
|
return React__default["default"].createElement(Provider, { value: contextValue }, children);
|
|
4217
4223
|
}
|
|
@@ -4264,6 +4270,9 @@ function useIntersectionRef(element, intersectionObserverOptions) {
|
|
|
4264
4270
|
var ComboboxMatch = function (_a) {
|
|
4265
4271
|
var text = _a.children;
|
|
4266
4272
|
var inputValue = useComboboxContext().inputValue;
|
|
4273
|
+
if (!text) {
|
|
4274
|
+
return React__default["default"].createElement("span", null);
|
|
4275
|
+
}
|
|
4267
4276
|
if (!(inputValue === null || inputValue === void 0 ? void 0 : inputValue.length)) {
|
|
4268
4277
|
return React__default["default"].createElement("span", null, text);
|
|
4269
4278
|
}
|
|
@@ -4281,10 +4290,10 @@ var ComboboxMatch = function (_a) {
|
|
|
4281
4290
|
React__default["default"].createElement("span", null, matchAfter)));
|
|
4282
4291
|
};
|
|
4283
4292
|
var ComboboxOption = React.forwardRef(function (_a, ref) {
|
|
4284
|
-
var className = _a.className, children = _a.children, disabled = _a.disabled, propId = _a.id, description = _a.description, propValue = _a.value, props = tslib.__rest(_a, ["className", "children", "disabled", "id", "description", "value"]);
|
|
4293
|
+
var className = _a.className, children = _a.children, disabled = _a.disabled, propId = _a.id, description = _a.description, propValue = _a.value, formValue = _a.formValue, props = tslib.__rest(_a, ["className", "children", "disabled", "id", "description", "value", "formValue"]);
|
|
4285
4294
|
var _b = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox-option'), 1), id = _b[0];
|
|
4286
4295
|
var _c = useListboxContext(), selected = _c.selected, active = _c.active;
|
|
4287
|
-
var _d = useComboboxContext(), matches = _d.matches, setMatchingOptions = _d.setMatchingOptions;
|
|
4296
|
+
var _d = useComboboxContext(), selectedValue = _d.selectedValue, matches = _d.matches, setMatchingOptions = _d.setMatchingOptions, setFormValue = _d.setFormValue;
|
|
4288
4297
|
var comboboxOptionRef = useSharedRef(ref);
|
|
4289
4298
|
var intersectionRef = useIntersectionRef(comboboxOptionRef, {
|
|
4290
4299
|
root: null,
|
|
@@ -4312,6 +4321,15 @@ var ComboboxOption = React.forwardRef(function (_a, ref) {
|
|
|
4312
4321
|
});
|
|
4313
4322
|
}
|
|
4314
4323
|
}, [isActive]);
|
|
4324
|
+
React.useEffect(function () {
|
|
4325
|
+
var _a;
|
|
4326
|
+
var comboboxValue = typeof propValue !== 'undefined'
|
|
4327
|
+
? propValue
|
|
4328
|
+
: (_a = comboboxOptionRef.current) === null || _a === void 0 ? void 0 : _a.innerText;
|
|
4329
|
+
if (selectedValue === comboboxValue) {
|
|
4330
|
+
setFormValue(typeof formValue === 'undefined' ? comboboxValue : formValue);
|
|
4331
|
+
}
|
|
4332
|
+
}, [selectedValue, formValue]);
|
|
4315
4333
|
React.useEffect(function () {
|
|
4316
4334
|
if (isMatching) {
|
|
4317
4335
|
setMatchingOptions(function (options) {
|
|
@@ -4360,13 +4378,14 @@ var ComboboxNoResults = function (_a) {
|
|
|
4360
4378
|
return (React__default["default"].createElement("div", { className: "ComboboxListbox__empty", role: "alert", "aria-live": "polite" }, children || 'No results found.'));
|
|
4361
4379
|
};
|
|
4362
4380
|
var Combobox = React.forwardRef(function (_a, ref) {
|
|
4363
|
-
var propId = _a.id, className = _a.className, label = _a.label, children = _a.children, _b = _a.options, options = _b === void 0 ? [] : _b, propValue = _a.value, defaultValue = _a.defaultValue, _c = _a.requiredText, requiredText = _c === void 0 ? 'Required' : _c, error = _a.error, _d = _a.autocomplete, autocomplete = _d === void 0 ? 'manual' : _d, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, onChange = _a.onChange, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, renderNoResults = _a.renderNoResults, portal = _a.portal, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "renderNoResults", "portal"]);
|
|
4381
|
+
var propId = _a.id, className = _a.className, label = _a.label, children = _a.children, _b = _a.options, options = _b === void 0 ? [] : _b, propValue = _a.value, defaultValue = _a.defaultValue, _c = _a.requiredText, requiredText = _c === void 0 ? 'Required' : _c, error = _a.error, _d = _a.autocomplete, autocomplete = _d === void 0 ? 'manual' : _d, onSelectionChange = _a.onSelectionChange, onActiveChange = _a.onActiveChange, onChange = _a.onChange, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, name = _a.name, renderNoResults = _a.renderNoResults, portal = _a.portal, props = tslib.__rest(_a, ["id", "className", "label", "children", "options", "value", "defaultValue", "requiredText", "error", "autocomplete", "onSelectionChange", "onActiveChange", "onChange", "onKeyDown", "onFocus", "onBlur", "name", "renderNoResults", "portal"]);
|
|
4364
4382
|
var _e = tslib.__read(React.useState(defaultValue || propValue || ''), 2), value = _e[0], setValue = _e[1];
|
|
4365
4383
|
var _f = tslib.__read(React.useState(new Map()), 2), matchingOptions = _f[0], setMatchingOptions = _f[1];
|
|
4366
4384
|
var _g = tslib.__read(React.useState(value || ''), 2), selectedValue = _g[0], setSelectedValue = _g[1];
|
|
4367
|
-
var _h = tslib.__read(React.useState(
|
|
4368
|
-
var _j = tslib.__read(React.useState(
|
|
4369
|
-
var _k = tslib.__read(
|
|
4385
|
+
var _h = tslib.__read(React.useState(''), 2), formValue = _h[0], setFormValue = _h[1];
|
|
4386
|
+
var _j = tslib.__read(React.useState(false), 2), open = _j[0], setOpen = _j[1];
|
|
4387
|
+
var _k = tslib.__read(React.useState(null), 2), activeDescendant = _k[0], setActiveDescendant = _k[1];
|
|
4388
|
+
var _l = tslib.__read(propId ? [propId] : nextId.useId(1, 'combobox'), 1), id = _l[0];
|
|
4370
4389
|
var comboboxRef = useSharedRef(ref);
|
|
4371
4390
|
var inputRef = React.useRef(null);
|
|
4372
4391
|
var listboxRef = React.useRef(null);
|
|
@@ -4395,7 +4414,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
|
|
|
4395
4414
|
setActiveDescendant(null);
|
|
4396
4415
|
}
|
|
4397
4416
|
if (open && autocomplete === 'automatic' && !selectedValue) {
|
|
4398
|
-
// Fire
|
|
4417
|
+
// Fire a Home keydown event on listbox to ensure the first item is selected
|
|
4399
4418
|
triggerListboxKeyDown(Home);
|
|
4400
4419
|
}
|
|
4401
4420
|
}, [open]);
|
|
@@ -4536,10 +4555,11 @@ var Combobox = React.forwardRef(function (_a, ref) {
|
|
|
4536
4555
|
var noMatchingOptions = !!(value === null || value === void 0 ? void 0 : value.length) && !matchingOptions.size && (React__default["default"].createElement(NoMatchingOptions, null));
|
|
4537
4556
|
var comboboxListbox = (React__default["default"].createElement(Listbox, { className: classNames__default["default"]('Combobox__listbox', {
|
|
4538
4557
|
'Combobox__listbox--open': open
|
|
4539
|
-
}), role: "listbox", "aria-labelledby": "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: selectedValue, onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant":
|
|
4558
|
+
}), role: "listbox", "aria-labelledby": "".concat(id, "-label"), id: "".concat(id, "-listbox"), value: selectedValue, onMouseDown: handleComboboxOptionMouseDown, onClick: handleComboboxOptionClick, onSelectionChange: handleSelectionChange, onActiveChange: handleActiveChange, ref: listboxRef, tabIndex: undefined, "aria-activedescendant": undefined },
|
|
4540
4559
|
comboboxOptions,
|
|
4541
4560
|
noMatchingOptions));
|
|
4542
4561
|
return (React__default["default"].createElement("div", { id: id, className: classNames__default["default"]('Combobox', className), ref: comboboxRef },
|
|
4562
|
+
name && React__default["default"].createElement("input", { type: "hidden", name: name, value: formValue }),
|
|
4543
4563
|
React__default["default"].createElement("label", { className: classNames__default["default"]('Field__label', {
|
|
4544
4564
|
'Field__label--is-required': isRequired,
|
|
4545
4565
|
'Field__label--has-error': hasError
|
|
@@ -4554,7 +4574,7 @@ var Combobox = React.forwardRef(function (_a, ref) {
|
|
|
4554
4574
|
onClick: handleInputClick },
|
|
4555
4575
|
React__default["default"].createElement("input", tslib.__assign({ type: "text", id: "".concat(id, "-input"), ref: inputRef, value: value, role: "combobox", "aria-autocomplete": !isAutoComplete ? 'none' : 'list', "aria-controls": "".concat(id, "-listbox"), "aria-expanded": open, "aria-haspopup": "listbox", "aria-activedescendant": open && activeDescendant ? activeDescendant.element.id : undefined }, props, { onChange: handleChange, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur })),
|
|
4556
4576
|
React__default["default"].createElement("span", { className: "Combobox__arrow" })),
|
|
4557
|
-
React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: value, selectedValue: selectedValue, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions }, portal
|
|
4577
|
+
React__default["default"].createElement(ComboboxProvider, { autocomplete: autocomplete, inputValue: value, formValue: formValue, selectedValue: selectedValue, matches: !isAutoComplete || defaultAutoCompleteMatches, matchingOptions: matchingOptions, setMatchingOptions: setMatchingOptions, setFormValue: setFormValue }, portal
|
|
4558
4578
|
? reactDom.createPortal(comboboxListbox, portal instanceof HTMLElement
|
|
4559
4579
|
? portal
|
|
4560
4580
|
: portal.current ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deque/cauldron-react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0-canary.83e0212e",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
6
6
|
"homepage": "https://cauldron.dequelabs.com/",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"@babel/preset-env": "^7.22.10",
|
|
41
41
|
"@babel/preset-react": "^7.22.5",
|
|
42
42
|
"@babel/preset-typescript": "^7.22.5",
|
|
43
|
-
"@babel/register": "^7.22.5",
|
|
44
43
|
"@rollup/plugin-commonjs": "^14.0.0",
|
|
45
44
|
"@rollup/plugin-dynamic-import-vars": "^1.4.2",
|
|
46
45
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
@@ -54,28 +53,19 @@
|
|
|
54
53
|
"autoprefixer": "^9.7.6",
|
|
55
54
|
"babel-plugin-module-resolver": "^4.0.0",
|
|
56
55
|
"babel-plugin-transform-export-extensions": "^6.22.0",
|
|
57
|
-
"closest": "^0.0.1",
|
|
58
56
|
"concurrently": "^5.3.0",
|
|
59
57
|
"enzyme": "^3.11.0",
|
|
60
58
|
"enzyme-adapter-react-16": "^1.15.2",
|
|
61
59
|
"jest": "^24.7.1",
|
|
62
60
|
"jest-axe": "^3.4.0",
|
|
63
|
-
"jsdom": "^16.2.2",
|
|
64
|
-
"jsdom-global": "^3.0.2",
|
|
65
61
|
"nyc": "^15.0.1",
|
|
66
62
|
"postcss-cli": "^7.1.1",
|
|
67
63
|
"postcss-import": "^12.0.1",
|
|
68
64
|
"postcss-loader": "^3.0.0",
|
|
69
|
-
"prettier": "^2.0.5",
|
|
70
|
-
"proxyquire": "^2.1.3",
|
|
71
65
|
"react": "^16.13.1",
|
|
72
66
|
"react-dom": "^16.13.1",
|
|
73
|
-
"react-element-to-jsx-string": "^14.3.1",
|
|
74
|
-
"react-helmet": "^6.0.0",
|
|
75
|
-
"react-router-dom": "^5.1.2",
|
|
76
67
|
"rollup": "^2.23.0",
|
|
77
68
|
"sinon": "^10.0.0",
|
|
78
|
-
"ts-node": "^10.9.1",
|
|
79
69
|
"typescript": "~5.0.0"
|
|
80
70
|
},
|
|
81
71
|
"repository": {
|
|
@@ -120,4 +110,4 @@
|
|
|
120
110
|
"\\.svg$": "<rootDir>/__tests__/svgMock.js"
|
|
121
111
|
}
|
|
122
112
|
}
|
|
123
|
-
}
|
|
113
|
+
}
|