@react-md/autocomplete
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -6,2 +6,19 @@ # Change Log | ||
# [3.1.0](https://github.com/mlaursen/react-md/compare/v3.0.1...v3.1.0) (2021-09-10) | ||
### Bug Fixes | ||
* **typescript:** updated all array types to be readonly ([8f71bcb](https://github.com/mlaursen/react-md/commit/8f71bcbde12928434975c6836079c3dda7c6ab1f)) | ||
### Other Internal Changes | ||
* ran `yarn format` to include new files ([48d3d7f](https://github.com/mlaursen/react-md/commit/48d3d7fddb0435edf7dec9d0ba38cf3f0f251709)) | ||
## [3.0.1](https://github.com/mlaursen/react-md/compare/v3.0.0...v3.0.1) (2021-08-15) | ||
@@ -8,0 +25,0 @@ |
@@ -23,6 +23,10 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -100,3 +104,3 @@ import React, { forwardRef } from "react"; | ||
if (isListboxOptionProps(datum)) { | ||
optionProps = omit(datum, __spreadArray([labelKey, valueKey], omitKeys)); | ||
optionProps = omit(datum, __spreadArray([labelKey, valueKey], omitKeys, true)); | ||
} | ||
@@ -103,0 +107,0 @@ return (React.createElement(Option, __assign({ key: resultId }, optionProps, { id: resultId, selected: false, focused: resultId === activeId, ref: itemRefs[i], onClick: function () { return handleAutoComplete(i); } }), |
@@ -43,6 +43,10 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -63,4 +67,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
var utils_2 = require("./utils"); | ||
var block = utils_1.bem("rmd-autocomplate"); | ||
var listbox = utils_1.bem("rmd-listbox"); | ||
var block = (0, utils_1.bem)("rmd-autocomplate"); | ||
var listbox = (0, utils_1.bem)("rmd-listbox"); | ||
var DEFAULT_FILTER_OPTIONS = { | ||
@@ -75,3 +79,3 @@ trim: true, | ||
*/ | ||
exports.AutoComplete = react_1.forwardRef(function AutoComplete(_a, forwardedRef) { | ||
exports.AutoComplete = (0, react_1.forwardRef)(function AutoComplete(_a, forwardedRef) { | ||
var _b = _a.autoComplete, autoComplete = _b === void 0 ? "list" : _b, data = _a.data, _c = _a.filter, filter = _c === void 0 ? "case-insensitive" : _c, _d = _a.filterOptions, filterOptions = _d === void 0 ? DEFAULT_FILTER_OPTIONS : _d, _e = _a.filterOnNoValue, filterOnNoValue = _e === void 0 ? false : _e, className = _a.className, onBlur = _a.onBlur, onFocus = _a.onFocus, onClick = _a.onClick, onKeyDown = _a.onKeyDown, onChange = _a.onChange, containerProps = _a.containerProps, _f = _a.portal, portal = _f === void 0 ? false : _f, portalInto = _a.portalInto, portalIntoId = _a.portalIntoId, listboxStyle = _a.listboxStyle, listboxClassName = _a.listboxClassName, onAutoComplete = _a.onAutoComplete, _g = _a.clearOnAutoComplete, clearOnAutoComplete = _g === void 0 ? false : _g, _h = _a.labelKey, labelKey = _h === void 0 ? "label" : _h, _j = _a.valueKey, valueKey = _j === void 0 ? "value" : _j, _k = _a.getResultId, getResultId = _k === void 0 ? utils_2.getResultId : _k, _l = _a.getResultLabel, getResultLabel = _l === void 0 ? utils_2.getResultLabel : _l, _m = _a.getResultValue, getResultValue = _m === void 0 ? utils_2.getResultValue : _m, _o = _a.highlight, highlight = _o === void 0 ? false : _o, _p = _a.highlightReapeating, highlightReapeating = _p === void 0 ? false : _p, highlightStyle = _a.highlightStyle, highlightClassName = _a.highlightClassName, _q = _a.anchor, anchor = _q === void 0 ? utils_1.BELOW_CENTER_ANCHOR : _q, _r = _a.listboxWidth, listboxWidth = _r === void 0 ? "equal" : _r, _s = _a.xMargin, xMargin = _s === void 0 ? 0 : _s, _t = _a.yMargin, yMargin = _t === void 0 ? 0 : _t, _u = _a.vwMargin, vwMargin = _u === void 0 ? 16 : _u, _v = _a.vhMargin, vhMargin = _v === void 0 ? 16 : _v, _w = _a.transformOrigin, transformOrigin = _w === void 0 ? true : _w, _x = _a.preventOverlap, preventOverlap = _x === void 0 ? true : _x, _y = _a.disableVHBounds, disableVHBounds = _y === void 0 ? false : _y, _z = _a.disableSwapping, disableSwapping = _z === void 0 ? true : _z, disableShowOnFocus = _a.disableShowOnFocus, _0 = _a.closeOnResize, closeOnResize = _0 === void 0 ? false : _0, _1 = _a.closeOnScroll, closeOnScroll = _1 === void 0 ? false : _1, _2 = _a.omitKeys, omitKeys = _2 === void 0 ? EMPTY_LIST : _2, propValue = _a.value, defaultValue = _a.defaultValue, beforeResultsChildren = _a.beforeResultsChildren, afterResultsChildren = _a.afterResultsChildren, props = __rest(_a, ["autoComplete", "data", "filter", "filterOptions", "filterOnNoValue", "className", "onBlur", "onFocus", "onClick", "onKeyDown", "onChange", "containerProps", "portal", "portalInto", "portalIntoId", "listboxStyle", "listboxClassName", "onAutoComplete", "clearOnAutoComplete", "labelKey", "valueKey", "getResultId", "getResultLabel", "getResultValue", "highlight", "highlightReapeating", "highlightStyle", "highlightClassName", "anchor", "listboxWidth", "xMargin", "yMargin", "vwMargin", "vhMargin", "transformOrigin", "preventOverlap", "disableVHBounds", "disableSwapping", "disableShowOnFocus", "closeOnResize", "closeOnScroll", "omitKeys", "value", "defaultValue", "beforeResultsChildren", "afterResultsChildren"]); | ||
@@ -83,3 +87,3 @@ var id = props.id; | ||
var isInlineAutocomplete = autoComplete === "inline" || autoComplete === "both"; | ||
var _3 = useAutoComplete_1.useAutoComplete({ | ||
var _3 = (0, useAutoComplete_1.useAutoComplete)({ | ||
suggestionsId: suggestionsId, | ||
@@ -120,5 +124,5 @@ defaultValue: defaultValue, | ||
return (react_1.default.createElement(react_1.default.Fragment, null, | ||
react_1.default.createElement(form_1.TextField, __assign({}, props, { "aria-autocomplete": autoComplete, "aria-controls": comboboxId, "aria-activedescendant": activeId, autoComplete: "off", value: propValue !== null && propValue !== void 0 ? propValue : match, onBlur: handleBlur, onFocus: handleFocus, onClick: handleClick, onKeyDown: handleKeyDown, onChange: handleChange, ref: ref, className: classnames_1.default(block(), className), containerProps: __assign(__assign({}, containerProps), { "aria-haspopup": "listbox", "aria-owns": suggestionsId, "aria-expanded": visible, id: comboboxId, role: "combobox" }) })), | ||
react_1.default.createElement(form_1.TextField, __assign({}, props, { "aria-autocomplete": autoComplete, "aria-controls": comboboxId, "aria-activedescendant": activeId, autoComplete: "off", value: propValue !== null && propValue !== void 0 ? propValue : match, onBlur: handleBlur, onFocus: handleFocus, onClick: handleClick, onKeyDown: handleKeyDown, onChange: handleChange, ref: ref, className: (0, classnames_1.default)(block(), className), containerProps: __assign(__assign({}, containerProps), { "aria-haspopup": "listbox", "aria-owns": suggestionsId, "aria-expanded": visible, id: comboboxId, role: "combobox" }) })), | ||
react_1.default.createElement(transition_1.ScaleTransition, __assign({ portal: portal, portalInto: portalInto, portalIntoId: portalIntoId, vertical: true, visible: visible }, transitionHooks), | ||
react_1.default.createElement(list_1.List, { id: suggestionsId, role: "listbox", ref: listboxRef, style: fixedStyle, className: classnames_1.default(listbox({ temporary: true }), listboxClassName) }, | ||
react_1.default.createElement(list_1.List, { id: suggestionsId, role: "listbox", ref: listboxRef, style: fixedStyle, className: (0, classnames_1.default)(listbox({ temporary: true }), listboxClassName) }, | ||
beforeResultsChildren, | ||
@@ -128,4 +132,4 @@ filteredData.map(function (datum, i) { | ||
var optionProps; | ||
if (form_1.isListboxOptionProps(datum)) { | ||
optionProps = utils_1.omit(datum, __spreadArray([labelKey, valueKey], omitKeys)); | ||
if ((0, form_1.isListboxOptionProps)(datum)) { | ||
optionProps = (0, utils_1.omit)(datum, __spreadArray([labelKey, valueKey], omitKeys, true)); | ||
} | ||
@@ -132,0 +136,0 @@ return (react_1.default.createElement(form_1.Option, __assign({ key: resultId }, optionProps, { id: resultId, selected: false, focused: resultId === activeId, ref: itemRefs[i], onClick: function () { return handleAutoComplete(i); } }), |
@@ -29,3 +29,3 @@ "use strict"; | ||
i > 0 && children.substring(0, i), | ||
react_1.default.createElement("span", { id: id, style: style, className: classnames_1.default("rmd-typography--bold", className) }, children.substring(i, end)), | ||
react_1.default.createElement("span", { id: id, style: style, className: (0, classnames_1.default)("rmd-typography--bold", className) }, children.substring(i, end)), | ||
end < children.length && (react_1.default.createElement(HighlightedResult, { style: style, className: className, value: value, enabled: enabled && repeatable, repeatable: repeatable, index: index + 1 }, children.substring(end))))); | ||
@@ -32,0 +32,0 @@ } |
@@ -27,5 +27,5 @@ "use strict"; | ||
var suggestionsId = _a.suggestionsId, data = _a.data, propValue = _a.propValue, _c = _a.defaultValue, defaultValue = _c === void 0 ? "" : _c, filterFn = _a.filter, filterOptions = _a.filterOptions, filterOnNoValue = _a.filterOnNoValue, valueKey = _a.valueKey, getResultId = _a.getResultId, getResultValue = _a.getResultValue, onBlur = _a.onBlur, onFocus = _a.onFocus, onClick = _a.onClick, onChange = _a.onChange, onKeyDown = _a.onKeyDown, forwardedRef = _a.forwardedRef, onAutoComplete = _a.onAutoComplete, clearOnAutoComplete = _a.clearOnAutoComplete, anchor = _a.anchor, xMargin = _a.xMargin, yMargin = _a.yMargin, vwMargin = _a.vwMargin, vhMargin = _a.vhMargin, transformOrigin = _a.transformOrigin, listboxWidth = _a.listboxWidth, listboxStyle = _a.listboxStyle, preventOverlap = _a.preventOverlap, disableSwapping = _a.disableSwapping, disableVHBounds = _a.disableVHBounds, closeOnResize = _a.closeOnResize, closeOnScroll = _a.closeOnScroll, propDisableShowOnFocus = _a.disableShowOnFocus, isListAutocomplete = _a.isListAutocomplete, isInlineAutocomplete = _a.isInlineAutocomplete; | ||
var _d = utils_1.useEnsuredRef(forwardedRef), ref = _d[0], refHandler = _d[1]; | ||
var filter = utils_2.getFilterFunction(filterFn); | ||
var _e = react_1.useState(function () { | ||
var _d = (0, utils_1.useEnsuredRef)(forwardedRef), ref = _d[0], refHandler = _d[1]; | ||
var filter = (0, utils_2.getFilterFunction)(filterFn); | ||
var _e = (0, react_1.useState)(function () { | ||
var _a; | ||
@@ -48,3 +48,3 @@ var options = __assign(__assign({}, filterOptions), { valueKey: valueKey, getItemValue: getResultValue, startsWith: (_a = filterOptions === null || filterOptions === void 0 ? void 0 : filterOptions.startsWith) !== null && _a !== void 0 ? _a : isInlineAutocomplete }); | ||
var value = propValue !== null && propValue !== void 0 ? propValue : stateValue; | ||
var setValue = react_1.useCallback(function (nextValue) { | ||
var setValue = (0, react_1.useCallback)(function (nextValue) { | ||
var isBackspace = value.length > nextValue.length || | ||
@@ -83,4 +83,4 @@ (!!match && value.length === nextValue.length); | ||
// for showing when the value/ filtered data list change | ||
var autocompleted = react_1.useRef(false); | ||
var handleChange = react_1.useCallback(function (event) { | ||
var autocompleted = (0, react_1.useRef)(false); | ||
var handleChange = (0, react_1.useCallback)(function (event) { | ||
if (onChange) { | ||
@@ -92,7 +92,7 @@ onChange(event); | ||
}, [setValue, onChange]); | ||
var _g = utils_1.useToggle(false), visible = _g[0], show = _g[1], hide = _g[2]; | ||
var isTouch = utils_1.useIsUserInteractionMode("touch"); | ||
var _g = (0, utils_1.useToggle)(false), visible = _g[0], show = _g[1], hide = _g[2]; | ||
var isTouch = (0, utils_1.useIsUserInteractionMode)("touch"); | ||
var disableShowOnFocus = propDisableShowOnFocus !== null && propDisableShowOnFocus !== void 0 ? propDisableShowOnFocus : isTouch; | ||
var focused = react_1.useRef(false); | ||
var handleBlur = react_1.useCallback(function (event) { | ||
var focused = (0, react_1.useRef)(false); | ||
var handleBlur = (0, react_1.useCallback)(function (event) { | ||
if (onBlur) { | ||
@@ -103,3 +103,3 @@ onBlur(event); | ||
}, [onBlur]); | ||
var handleFocus = react_1.useCallback(function (event) { | ||
var handleFocus = (0, react_1.useCallback)(function (event) { | ||
if (onFocus) { | ||
@@ -116,3 +116,3 @@ onFocus(event); | ||
}, [filteredData, isListAutocomplete, onFocus, show, disableShowOnFocus]); | ||
var handleClick = react_1.useCallback(function (event) { | ||
var handleClick = (0, react_1.useCallback)(function (event) { | ||
if (onClick) { | ||
@@ -133,3 +133,3 @@ onClick(event); | ||
}, [disableShowOnFocus, filteredData.length, isListAutocomplete, onClick, show]); | ||
var handleAutoComplete = react_1.useCallback(function (index) { | ||
var handleAutoComplete = (0, react_1.useCallback)(function (index) { | ||
var result = filteredData[index]; | ||
@@ -157,4 +157,4 @@ var resultValue = getResultValue(result, valueKey); | ||
]); | ||
var listboxRef = react_1.useRef(null); | ||
var _h = utils_1.useActiveDescendantMovement(__assign(__assign({}, utils_1.MovementPresets.VERTICAL_COMBOBOX), { getId: getResultId, items: filteredData, baseId: suggestionsId, onChange: function (_a, itemRefs) { | ||
var listboxRef = (0, react_1.useRef)(null); | ||
var _h = (0, utils_1.useActiveDescendantMovement)(__assign(__assign({}, utils_1.MovementPresets.VERTICAL_COMBOBOX), { getId: getResultId, items: filteredData, baseId: suggestionsId, onChange: function (_a, itemRefs) { | ||
var index = _a.index, items = _a.items, target = _a.target; | ||
@@ -168,3 +168,3 @@ // the default scroll into view behavior for aria-activedescendant | ||
if (item && listbox && listbox.scrollHeight > listbox.offsetHeight) { | ||
utils_1.scrollIntoView(listbox, item); | ||
(0, utils_1.scrollIntoView)(listbox, item); | ||
} | ||
@@ -236,3 +236,3 @@ if (!isInlineAutocomplete) { | ||
} })), activeId = _h.activeId, itemRefs = _h.itemRefs, handleKeyDown = _h.onKeyDown, focusedIndex = _h.focusedIndex, setFocusedIndex = _h.setFocusedIndex; | ||
utils_1.useCloseOnOutsideClick({ | ||
(0, utils_1.useCloseOnOutsideClick)({ | ||
enabled: visible, | ||
@@ -242,3 +242,3 @@ element: ref.current, | ||
}); | ||
var _j = transition_1.useFixedPositioning({ | ||
var _j = (0, transition_1.useFixedPositioning)({ | ||
fixedTo: function () { return ref.current; }, | ||
@@ -263,3 +263,3 @@ anchor: anchor, | ||
}), style = _j.style, onEnter = _j.onEnter, onEntering = _j.onEntering, onEntered = _j.onEntered, onExited = _j.onExited, updateStyle = _j.updateStyle; | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (!focused.current || autocompleted.current) { | ||
@@ -278,3 +278,3 @@ return; | ||
}, [filteredData, value]); | ||
react_1.useEffect(function () { | ||
(0, react_1.useEffect)(function () { | ||
if (!visible) { | ||
@@ -281,0 +281,0 @@ setFocusedIndex(-1); |
{ | ||
"name": "@react-md/autocomplete", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -34,10 +34,10 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@react-md/form": "^3.0.1", | ||
"@react-md/list": "^3.0.1", | ||
"@react-md/portal": "^3.0.0", | ||
"@react-md/states": "^3.0.1", | ||
"@react-md/theme": "^3.0.0", | ||
"@react-md/transition": "^3.0.1", | ||
"@react-md/typography": "^3.0.0", | ||
"@react-md/utils": "^3.0.0", | ||
"@react-md/form": "^3.1.0", | ||
"@react-md/list": "^3.1.0", | ||
"@react-md/portal": "^3.1.0", | ||
"@react-md/states": "^3.1.0", | ||
"@react-md/theme": "^3.1.0", | ||
"@react-md/transition": "^3.1.0", | ||
"@react-md/typography": "^3.1.0", | ||
"@react-md/utils": "^3.1.0", | ||
"classnames": "^2.3.1" | ||
@@ -59,3 +59,3 @@ }, | ||
}, | ||
"gitHead": "68149668ebc79c4bbcbb2875d65b9ac243e12c77" | ||
"gitHead": "5891a3255f12fb34d2cc82d81d10f85f712a21e8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197981
3568
Updated@react-md/form@^3.1.0
Updated@react-md/list@^3.1.0
Updated@react-md/portal@^3.1.0
Updated@react-md/states@^3.1.0
Updated@react-md/theme@^3.1.0
Updated@react-md/transition@^3.1.0
Updated@react-md/typography@^3.1.0
Updated@react-md/utils@^3.1.0