@elliemae/ds-form-combobox 3.80.0-next.72 → 3.80.0-next.76
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/cjs/DSCommonComboboxPropsT.js +7 -3
- package/dist/cjs/DSCommonComboboxPropsT.js.map +2 -2
- package/dist/cjs/config/useComboBox.js +21 -6
- package/dist/cjs/config/useComboBox.js.map +2 -2
- package/dist/cjs/parts/DropdownIndicator.js +4 -3
- package/dist/cjs/parts/DropdownIndicator.js.map +2 -2
- package/dist/cjs/parts/Section.js +18 -8
- package/dist/cjs/parts/Section.js.map +2 -2
- package/dist/cjs/parts/container/Container.js +5 -2
- package/dist/cjs/parts/container/Container.js.map +2 -2
- package/dist/cjs/parts/container/styled.js +4 -4
- package/dist/cjs/parts/container/styled.js.map +2 -2
- package/dist/cjs/parts/controls/Controls.js +10 -19
- package/dist/cjs/parts/controls/Controls.js.map +2 -2
- package/dist/cjs/parts/controls/styled.js +7 -7
- package/dist/cjs/parts/controls/styled.js.map +2 -2
- package/dist/cjs/parts/controls/useOnPillsNavigation.js +5 -13
- package/dist/cjs/parts/controls/useOnPillsNavigation.js.map +2 -2
- package/dist/cjs/parts/controls-input/ControlsInput.js +20 -19
- package/dist/cjs/parts/controls-input/ControlsInput.js.map +2 -2
- package/dist/cjs/parts/controls-input/styled.js +5 -2
- package/dist/cjs/parts/controls-input/styled.js.map +2 -2
- package/dist/cjs/parts/controls-input/useKeyboardNavigation.js +22 -15
- package/dist/cjs/parts/controls-input/useKeyboardNavigation.js.map +2 -2
- package/dist/cjs/parts/controls-input/useMaskedOnChange.js +11 -4
- package/dist/cjs/parts/controls-input/useMaskedOnChange.js.map +2 -2
- package/dist/cjs/parts/menu-list/useItemRenderer.js +22 -11
- package/dist/cjs/parts/menu-list/useItemRenderer.js.map +2 -2
- package/dist/cjs/parts/multi-selected-values-container/RemovableSelectedValuePill.js +4 -3
- package/dist/cjs/parts/multi-selected-values-container/RemovableSelectedValuePill.js.map +2 -2
- package/dist/cjs/parts/multi-selected-values-container/useGroupPills.js +10 -2
- package/dist/cjs/parts/multi-selected-values-container/useGroupPills.js.map +2 -2
- package/dist/cjs/utils/listHelper.js +2 -0
- package/dist/cjs/utils/listHelper.js.map +2 -2
- package/dist/esm/DSCommonComboboxPropsT.js +7 -3
- package/dist/esm/DSCommonComboboxPropsT.js.map +2 -2
- package/dist/esm/config/useComboBox.js +22 -7
- package/dist/esm/config/useComboBox.js.map +2 -2
- package/dist/esm/parts/DropdownIndicator.js +5 -4
- package/dist/esm/parts/DropdownIndicator.js.map +2 -2
- package/dist/esm/parts/Section.js +18 -8
- package/dist/esm/parts/Section.js.map +2 -2
- package/dist/esm/parts/container/Container.js +5 -2
- package/dist/esm/parts/container/Container.js.map +2 -2
- package/dist/esm/parts/container/styled.js +5 -5
- package/dist/esm/parts/container/styled.js.map +2 -2
- package/dist/esm/parts/controls/Controls.js +10 -19
- package/dist/esm/parts/controls/Controls.js.map +2 -2
- package/dist/esm/parts/controls/styled.js +7 -7
- package/dist/esm/parts/controls/styled.js.map +2 -2
- package/dist/esm/parts/controls/useOnPillsNavigation.js +5 -13
- package/dist/esm/parts/controls/useOnPillsNavigation.js.map +2 -2
- package/dist/esm/parts/controls-input/ControlsInput.js +27 -20
- package/dist/esm/parts/controls-input/ControlsInput.js.map +2 -2
- package/dist/esm/parts/controls-input/styled.js +6 -3
- package/dist/esm/parts/controls-input/styled.js.map +2 -2
- package/dist/esm/parts/controls-input/useKeyboardNavigation.js +24 -16
- package/dist/esm/parts/controls-input/useKeyboardNavigation.js.map +2 -2
- package/dist/esm/parts/controls-input/useMaskedOnChange.js +11 -4
- package/dist/esm/parts/controls-input/useMaskedOnChange.js.map +2 -2
- package/dist/esm/parts/menu-list/useItemRenderer.js +24 -13
- package/dist/esm/parts/menu-list/useItemRenderer.js.map +2 -2
- package/dist/esm/parts/multi-selected-values-container/RemovableSelectedValuePill.js +5 -4
- package/dist/esm/parts/multi-selected-values-container/RemovableSelectedValuePill.js.map +2 -2
- package/dist/esm/parts/multi-selected-values-container/useGroupPills.js +10 -2
- package/dist/esm/parts/multi-selected-values-container/useGroupPills.js.map +2 -2
- package/dist/esm/utils/listHelper.js +2 -0
- package/dist/esm/utils/listHelper.js.map +2 -2
- package/dist/types/ComboBoxCTX.d.ts +3 -1
- package/dist/types/config/useComboBox.d.ts +3 -1
- package/dist/types/parts/Section.d.ts +1 -0
- package/dist/types/parts/container/styled.d.ts +4 -4
- package/dist/types/parts/controls/styled.d.ts +7 -7
- package/dist/types/parts/controls-input/styled.d.ts +1 -1
- package/dist/types/parts/controls-input/useMaskedOnChange.d.ts +1 -1
- package/dist/types/utils/listHelper.d.ts +8 -0
- package/package.json +15 -15
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useContext, useMemo } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isLocked,
|
|
6
|
+
omitLockedHandlers,
|
|
7
|
+
useGetGlobalAttributes,
|
|
8
|
+
useOwnerProps,
|
|
9
|
+
resolveAriaDisabled
|
|
10
|
+
} from "@elliemae/ds-props-helpers";
|
|
5
11
|
import { mergeRefs } from "@elliemae/ds-system";
|
|
6
12
|
import { TruncatedText } from "../../TruncatedText.js";
|
|
7
13
|
import { ComboBoxContext } from "../../ComboBoxCTX.js";
|
|
@@ -54,34 +60,30 @@ const ControlsInput = () => {
|
|
|
54
60
|
onFocus: handleOnFocus,
|
|
55
61
|
onBlur: handleOnBlur
|
|
56
62
|
});
|
|
63
|
+
const readOnlyHelperId = `${instanceUid}-read-only-helper-msg`;
|
|
57
64
|
const actualAriaDescribedBy = useMemo(() => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return ariaDescribedBy;
|
|
63
|
-
}, [ariaDescribedBy, id]);
|
|
65
|
+
const internalIds = id ? `${id}_current_placeholder ${id}_feedback_message ${id}_error_message` : void 0;
|
|
66
|
+
return [ariaDescribedBy, internalIds, readOnly ? readOnlyHelperId : void 0].filter(Boolean).join(" ") || void 0;
|
|
67
|
+
}, [ariaDescribedBy, id, readOnly, readOnlyHelperId]);
|
|
64
68
|
const currentPlaceholder = useMemo(() => {
|
|
65
69
|
if (isArrayOfItems(selectedValues)) {
|
|
66
|
-
return `options ${selectedValues.map((item) => item.label).join(", ")} selected
|
|
70
|
+
return `options ${selectedValues.map((item) => item.label).join(", ")} selected.`;
|
|
67
71
|
}
|
|
68
72
|
if (isItemContainingALabel(selectedValues)) {
|
|
69
|
-
return `option ${selectedValues.label} selected
|
|
70
|
-
}
|
|
71
|
-
if (readOnly) {
|
|
72
|
-
return `${placeholder}. Read only`;
|
|
73
|
+
return `option ${selectedValues.label} selected.`;
|
|
73
74
|
}
|
|
74
75
|
return placeholder;
|
|
75
|
-
}, [placeholder, selectedValues
|
|
76
|
+
}, [placeholder, selectedValues]);
|
|
76
77
|
const activeDescendant = useMemo(() => {
|
|
77
78
|
if (!isLoading && hasFocus && menuState) {
|
|
78
79
|
return focusOptionIdx;
|
|
79
80
|
}
|
|
80
81
|
return void 0;
|
|
81
82
|
}, [focusOptionIdx, hasFocus, isLoading, menuState]);
|
|
82
|
-
const isNonInteractive =
|
|
83
|
+
const isNonInteractive = isLocked({ disabled, applyAriaDisabled, readOnly });
|
|
83
84
|
const handleOnPaste = (e) => {
|
|
84
85
|
e.preventDefault();
|
|
86
|
+
if (isNonInteractive) return;
|
|
85
87
|
setInputValue(e.clipboardData.getData("text/plain"));
|
|
86
88
|
internalRef.current?.focus();
|
|
87
89
|
};
|
|
@@ -100,6 +102,7 @@ const ControlsInput = () => {
|
|
|
100
102
|
),
|
|
101
103
|
menuState === false && !inline ? /* @__PURE__ */ jsx(StyledHiddenDiv, { id: `combo-listbox-${instanceUid}` }) : null,
|
|
102
104
|
/* @__PURE__ */ jsx(StyledHiddenDiv, { id: `${id}_current_placeholder`, children: currentPlaceholder }),
|
|
105
|
+
readOnly ? /* @__PURE__ */ jsx("p", { hidden: true, id: readOnlyHelperId, children: "Read only" }) : null,
|
|
103
106
|
/* @__PURE__ */ jsx(
|
|
104
107
|
StyledInput,
|
|
105
108
|
{
|
|
@@ -108,7 +111,7 @@ const ControlsInput = () => {
|
|
|
108
111
|
onBlur: handleOnBlur,
|
|
109
112
|
onFocus: handleOnFocus,
|
|
110
113
|
readOnly: readOnly || onlySelectable,
|
|
111
|
-
...globalAttrs,
|
|
114
|
+
...omitLockedHandlers(globalAttrs, isNonInteractive, "change"),
|
|
112
115
|
id,
|
|
113
116
|
"data-testid": ComboboxDataTestid.INPUT,
|
|
114
117
|
autoFocus,
|
|
@@ -120,7 +123,7 @@ const ControlsInput = () => {
|
|
|
120
123
|
"aria-autocomplete": "list",
|
|
121
124
|
role: "combobox",
|
|
122
125
|
disabled,
|
|
123
|
-
applyAriaDisabled: applyAriaDisabled
|
|
126
|
+
applyAriaDisabled: Boolean(applyAriaDisabled || readOnly),
|
|
124
127
|
style: { width },
|
|
125
128
|
innerRef: mergeRefs(innerRef, internalRef),
|
|
126
129
|
value: inputValue,
|
|
@@ -130,20 +133,24 @@ const ControlsInput = () => {
|
|
|
130
133
|
tabIndex,
|
|
131
134
|
withoutCaret: onlySelectable ?? false,
|
|
132
135
|
autoComplete: "off",
|
|
133
|
-
"aria-
|
|
136
|
+
"aria-disabled": resolveAriaDisabled({
|
|
137
|
+
disabled,
|
|
138
|
+
softLocked: isLocked({ applyAriaDisabled, readOnly }),
|
|
139
|
+
consumerValue: globalAttrs["aria-disabled"]
|
|
140
|
+
})
|
|
134
141
|
}
|
|
135
142
|
),
|
|
136
143
|
/* @__PURE__ */ jsx(
|
|
137
144
|
StyleHiddenInput,
|
|
138
145
|
{
|
|
139
146
|
type: "text",
|
|
140
|
-
disabled
|
|
141
|
-
readOnly,
|
|
147
|
+
disabled,
|
|
148
|
+
readOnly: Boolean(applyAriaDisabled || readOnly),
|
|
142
149
|
name: "hidden",
|
|
143
150
|
tabIndex: -1,
|
|
144
151
|
onPaste: handleOnPaste,
|
|
145
152
|
"aria-hidden": "true",
|
|
146
|
-
|
|
153
|
+
$applyAriaDisabled: Boolean(applyAriaDisabled || readOnly)
|
|
147
154
|
}
|
|
148
155
|
)
|
|
149
156
|
] });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/controls-input/ControlsInput.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo } from 'react';\nimport {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useMemo } from 'react';\nimport {\n isLocked,\n omitLockedHandlers,\n useGetGlobalAttributes,\n useOwnerProps,\n resolveAriaDisabled,\n} from '@elliemae/ds-props-helpers';\nimport { mergeRefs } from '@elliemae/ds-system';\nimport { TruncatedText } from '../../TruncatedText.js';\nimport { ComboBoxContext } from '../../ComboBoxCTX.js';\nimport { ComboboxDataTestid } from '../../ComboboxDataTestids.js';\nimport { isArrayOfItems } from '../../utils/listHelper.js';\nimport {\n StyledHiddenDiv,\n StyledInput,\n StyledInputPlaceHolder,\n StyledInputWidthReference,\n StyledInputWrapper,\n StyleHiddenInput,\n} from './styled.js';\nimport { useControlsInput } from './useControlsInput.js';\nimport { useKeyboardNavigation } from './useKeyboardNavigation.js';\nimport { isItemContainingALabel } from '../../utils/typeGuards.js';\n\n// aria-disabled is only printed as \"true\", and never next to the native disabled (`disabled` wins): a bare boolean\n// would print aria-disabled=\"false\" (PUI-16695)\nexport const ControlsInput = (): JSX.Element => {\n const {\n props,\n props: {\n autoFocus,\n inline,\n selectedValues,\n placeholder,\n disabled,\n innerRef,\n isLoading,\n onlySelectable,\n applyAriaDisabled,\n readOnly,\n ...restProps\n },\n focusOptionIdx,\n hasFocus,\n internalRef,\n inputValue,\n setInputValue,\n menuState,\n instanceUid,\n } = useContext(ComboBoxContext);\n const { onInputKeyDown } = useKeyboardNavigation();\n\n const { spanReference, width, spanReferenceText, showPlaceholder, handleOnBlur, handleOnChange, handleOnFocus } =\n useControlsInput();\n\n const { getOwnerProps, getOwnerPropsArguments } = useOwnerProps(props);\n\n const {\n tabIndex,\n id,\n 'aria-describedby': ariaDescribedBy,\n ...globalAttrs\n } = useGetGlobalAttributes(restProps, {\n onFocus: handleOnFocus,\n onBlur: handleOnBlur,\n });\n\n // Only readOnly references the helper: applyAriaDisabled alone does not render it (PUI-16695).\n const readOnlyHelperId = `${instanceUid}-read-only-helper-msg`;\n\n const actualAriaDescribedBy = useMemo(() => {\n const internalIds = id ? `${id}_current_placeholder ${id}_feedback_message ${id}_error_message` : undefined;\n return (\n [ariaDescribedBy, internalIds, readOnly ? readOnlyHelperId : undefined].filter(Boolean).join(' ') || undefined\n );\n }, [ariaDescribedBy, id, readOnly, readOnlyHelperId]);\n\n // \"Read only\" is announced once, through the hidden helper referenced by aria-describedby (see `readOnlyHelperId`)\n const currentPlaceholder = useMemo(() => {\n if (isArrayOfItems(selectedValues)) {\n return `options ${selectedValues.map((item) => item.label).join(', ')} selected.`;\n }\n if (isItemContainingALabel(selectedValues)) {\n return `option ${selectedValues.label} selected.`;\n }\n return placeholder;\n }, [placeholder, selectedValues]);\n\n const activeDescendant = useMemo(() => {\n if (!isLoading && hasFocus && menuState) {\n return focusOptionIdx;\n }\n return undefined;\n }, [focusOptionIdx, hasFocus, isLoading, menuState]);\n\n // any lock (PUI-16695): the consumer's action handlers are dropped from the global attributes spread below\n const isNonInteractive = isLocked({ disabled, applyAriaDisabled, readOnly });\n\n const handleOnPaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n if (isNonInteractive) return;\n setInputValue(e.clipboardData.getData('text/plain'));\n internalRef.current?.focus();\n };\n return (\n <StyledInputWrapper getOwnerProps={getOwnerProps}>\n <StyledInputWidthReference innerRef={spanReference}>{spanReferenceText}</StyledInputWidthReference>\n {showPlaceholder && (\n <StyledInputPlaceHolder\n variant=\"b2\"\n component=\"span\"\n getOwnerProps={getOwnerProps}\n aria-hidden=\"true\"\n $nonInteractive={isNonInteractive}\n >\n <TruncatedText value={showPlaceholder} />\n </StyledInputPlaceHolder>\n )}\n\n {/* The purpose of this div is to always have the 'combo-listbox-{uid}' present in the DOM */}\n {/* Fix for PUI-11597 */}\n {menuState === false && !inline ? <StyledHiddenDiv id={`combo-listbox-${instanceUid}`}></StyledHiddenDiv> : null}\n\n {/* The announcement of currentPlaceholder is being overridden by the value of actualAriaDescribedBy */}\n {/* and since this variable is necessary for the annoucement of FormLayoutBlockItem error and feedback */}\n {/* messages, we concatenate the value of actualPlaceholder with that aria description */}\n {/* Fix for PUI-9609 */}\n <StyledHiddenDiv id={`${id}_current_placeholder`}>{currentPlaceholder}</StyledHiddenDiv>\n\n {/* Read-only helper referenced by aria-describedby. Plain hidden <p>, not a styled slot: a new slot would */}\n {/* need a full slot contract. Rendered once per combobox (this component is the only input owner). */}\n {readOnly ? (\n <p hidden id={readOnlyHelperId}>\n Read only\n </p>\n ) : null}\n\n <StyledInput\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n onBlur={handleOnBlur}\n onFocus={handleOnFocus}\n readOnly={readOnly || onlySelectable}\n {...omitLockedHandlers(globalAttrs, isNonInteractive, 'change')}\n id={id}\n data-testid={ComboboxDataTestid.INPUT}\n autoFocus={autoFocus}\n placeholder={currentPlaceholder}\n aria-activedescendant={activeDescendant}\n aria-expanded={menuState}\n aria-controls={`combo-listbox-${instanceUid}`}\n aria-describedby={actualAriaDescribedBy}\n aria-autocomplete=\"list\"\n role=\"combobox\"\n disabled={disabled}\n applyAriaDisabled={Boolean(applyAriaDisabled || readOnly)}\n style={{ width }}\n innerRef={mergeRefs(innerRef, internalRef)}\n value={inputValue}\n type=\"text\"\n onKeyDown={onInputKeyDown}\n onChange={handleOnChange}\n tabIndex={tabIndex}\n withoutCaret={onlySelectable ?? false}\n autoComplete=\"off\"\n aria-disabled={resolveAriaDisabled({\n disabled,\n softLocked: isLocked({ applyAriaDisabled, readOnly }),\n consumerValue: globalAttrs['aria-disabled'],\n })}\n />\n {/* This input is used to handle the paste event */}\n <StyleHiddenInput\n type=\"text\"\n disabled={disabled}\n readOnly={Boolean(applyAriaDisabled || readOnly)}\n name=\"hidden\"\n tabIndex={-1}\n onPaste={handleOnPaste}\n aria-hidden=\"true\"\n $applyAriaDisabled={Boolean(applyAriaDisabled || readOnly)}\n />\n </StyledInputWrapper>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC0GnB,SACE,KADF;AA1GJ,SAAgB,YAAY,eAAe;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAIhC,MAAM,gBAAgB,MAAmB;AAC9C,QAAM;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,eAAe;AAC9B,QAAM,EAAE,eAAe,IAAI,sBAAsB;AAEjD,QAAM,EAAE,eAAe,OAAO,mBAAmB,iBAAiB,cAAc,gBAA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A,QACL;AAAA,QACA,UAAU,QAAQ,qBAAqB,QAAQ;AAAA,QAC/C,MAAK;AAAA,QACL,UAAU;AAAA,QACV,SAAS;AAAA,QACT,eAAY;AAAA,QACZ,oBAAoB,QAAQ,qBAAqB,QAAQ;AAAA;AAAA,IAC3D;AAAA,KACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { styled, css } from "@elliemae/ds-system";
|
|
2
|
+
import { styled, css, ariaDisabledInteractionCss, lockedStateInteractionCss } from "@elliemae/ds-system";
|
|
3
3
|
import { DSTypography, typographyFontFamily } from "@elliemae/ds-typography";
|
|
4
4
|
import { DSFormComboboxName, FORM_COMBOBOX_SLOTS } from "../../constants/index.js";
|
|
5
5
|
const b2InputTypography = css`
|
|
@@ -25,7 +25,7 @@ const StyleHiddenInput = styled("input")`
|
|
|
25
25
|
&:focus {
|
|
26
26
|
outline: none;
|
|
27
27
|
}
|
|
28
|
-
${
|
|
28
|
+
${lockedStateInteractionCss}
|
|
29
29
|
`;
|
|
30
30
|
const StyledInput = styled("input", {
|
|
31
31
|
name: DSFormComboboxName,
|
|
@@ -47,7 +47,10 @@ const StyledInput = styled("input", {
|
|
|
47
47
|
color: transparent;
|
|
48
48
|
}
|
|
49
49
|
transition: none;
|
|
50
|
-
${({ applyAriaDisabled }) => applyAriaDisabled && `
|
|
50
|
+
${({ applyAriaDisabled }) => applyAriaDisabled && css`
|
|
51
|
+
${ariaDisabledInteractionCss}
|
|
52
|
+
caret-color: transparent;
|
|
53
|
+
`}
|
|
51
54
|
`;
|
|
52
55
|
const StyledInputPlaceHolder = styled(DSTypography, {
|
|
53
56
|
name: DSFormComboboxName,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/controls-input/styled.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled, css } from '@elliemae/ds-system';\nimport { DSTypography, typographyFontFamily } from '@elliemae/ds-typography';\nimport { DSFormComboboxName, FORM_COMBOBOX_SLOTS } from '../../constants/index.js';\n\n/**\n * b2 typography mirrored as raw CSS for the native `<input>` and its hidden\n * width-measuring twin (`StyledInputWidthReference`). Neither can be a `DSTypography`\n * component \u2014 an `<input>` takes no children, and the reference must match the input's\n * exact font metrics or the autosizing (measured off the reference) drifts. ds-typography\n * does not export its VARIANTS_CSS_MAP, so the b2 values are duplicated here \u2014 keep in\n * sync with `ds-typography` b2 (`parts/variants/body.ts`). Text containers that CAN hold\n * children (placeholder, selection) use `styled(DSTypography)` with `variant=\"b2\"` instead.\n *\n * PUI-18977 \u2014 `typographyFontFamily` leads the block, as it does in b2 itself; without it\n * the input never resolves `theme.fonts.default`. It belongs in this shared block rather\n * than on `StyledInput` alone because font-family changes measured text width \u2014 the\n * reference twin must carry the identical family or the autosizing drifts. Precedent:\n * ds-form-input-text (PUI-18721).\n */\nconst b2InputTypography = css`\n ${typographyFontFamily}\n font-size: 0.8125rem;\n line-height: 1rem;\n font-weight: 400;\n @media (min-width: ${({ theme }) => theme.breakpoints.small}) {\n font-size: 1rem;\n line-height: 1.2307692308rem;\n }\n`;\n\nexport const StyleHiddenInput = styled('input')<{
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,QAAQ,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { styled, css, ariaDisabledInteractionCss, lockedStateInteractionCss } from '@elliemae/ds-system';\nimport { DSTypography, typographyFontFamily } from '@elliemae/ds-typography';\nimport { DSFormComboboxName, FORM_COMBOBOX_SLOTS } from '../../constants/index.js';\n\n/**\n * b2 typography mirrored as raw CSS for the native `<input>` and its hidden\n * width-measuring twin (`StyledInputWidthReference`). Neither can be a `DSTypography`\n * component \u2014 an `<input>` takes no children, and the reference must match the input's\n * exact font metrics or the autosizing (measured off the reference) drifts. ds-typography\n * does not export its VARIANTS_CSS_MAP, so the b2 values are duplicated here \u2014 keep in\n * sync with `ds-typography` b2 (`parts/variants/body.ts`). Text containers that CAN hold\n * children (placeholder, selection) use `styled(DSTypography)` with `variant=\"b2\"` instead.\n *\n * PUI-18977 \u2014 `typographyFontFamily` leads the block, as it does in b2 itself; without it\n * the input never resolves `theme.fonts.default`. It belongs in this shared block rather\n * than on `StyledInput` alone because font-family changes measured text width \u2014 the\n * reference twin must carry the identical family or the autosizing drifts. Precedent:\n * ds-form-input-text (PUI-18721).\n */\nconst b2InputTypography = css`\n ${typographyFontFamily}\n font-size: 0.8125rem;\n line-height: 1rem;\n font-weight: 400;\n @media (min-width: ${({ theme }) => theme.breakpoints.small}) {\n font-size: 1rem;\n line-height: 1.2307692308rem;\n }\n`;\n\nexport const StyleHiddenInput = styled('input')<{ $applyAriaDisabled: boolean }>`\n color: transparent;\n position: absolute;\n top: 0;\n left: 0;\n z-index: 2;\n border: none;\n outline: none;\n background: transparent;\n width: 100%;\n &:focus {\n outline: none;\n }\n ${lockedStateInteractionCss}\n`;\n\nexport const StyledInput = styled('input', {\n name: DSFormComboboxName,\n slot: FORM_COMBOBOX_SLOTS.INPUT,\n})<{ withoutCaret: boolean; applyAriaDisabled: boolean }>`\n ${b2InputTypography}\n background: transparent;\n border: none;\n overflow: hidden;\n padding: 0;\n z-index: 2;\n outline: none;\n color: ${(props) => (props.disabled ? props.theme.colors.neutral[600] : props.theme.colors.neutral[700])};\n &:focus {\n outline: none;\n }\n ${({ withoutCaret }) => withoutCaret && 'caret-color: transparent;'}\n &::placeholder {\n color: transparent;\n }\n transition: none;\n ${({ applyAriaDisabled }) =>\n applyAriaDisabled &&\n css`\n ${ariaDisabledInteractionCss}\n caret-color: transparent;\n `}\n`;\n\nexport const StyledInputPlaceHolder = styled(DSTypography, {\n name: DSFormComboboxName,\n slot: FORM_COMBOBOX_SLOTS.INPUT_PLACEHOLDER,\n})<{ $nonInteractive?: boolean }>`\n font-style: italic;\n color: ${(props) => (props.$nonInteractive ? props.theme.colors.neutral[600] : props.theme.colors.neutral[500])};\n position: absolute;\n display: flex;\n align-items: center;\n width: 100%;\n user-select: none;\n\n & span::after {\n content: '';\n padding: 1px;\n // solve italic font style clipping issue with overflow hidden.\n }\n`;\n\nexport const StyledInputWidthReference = styled.span`\n ${b2InputTypography}\n visibility: hidden;\n position: absolute;\n top: -9999px;\n z-index: 1;\n`;\n\nexport const StyledInputWrapper = styled('div', {\n name: DSFormComboboxName,\n slot: FORM_COMBOBOX_SLOTS.INPUT_FIELD_WRAPPER,\n})`\n position: relative;\n align-items: center;\n display: flex;\n /** PUI-15490 \u2014 the spec's 5px vertical padding lives on the text line (this wrapper, always\n * rendered) so the control height is constant and breathing room survives text resize.\n * Mobile keeps the legacy 1.25px \u2014 no mobile spec exists (KNOWN_INTENTIONAL_DEVIATIONS \u00A75).\n * The 1px right padding is pre-existing (caret clipping). */\n padding: 5px 1px 5px 0px;\n @media (max-width: ${({ theme }) => theme.breakpoints.small}) {\n padding: 1.25px 1px 1.25px 0px;\n }\n overflow: hidden;\n`;\n\nexport const StyledHiddenDiv = styled('div')`\n display: none;\n`;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,QAAQ,KAAK,4BAA4B,iCAAiC;AACnF,SAAS,cAAc,4BAA4B;AACnD,SAAS,oBAAoB,2BAA2B;AAiBxD,MAAM,oBAAoB;AAAA,IACtB,oBAAoB;AAAA;AAAA;AAAA;AAAA,uBAID,CAAC,EAAE,MAAM,MAAM,MAAM,YAAY,KAAK;AAAA;AAAA;AAAA;AAAA;AAMtD,MAAM,mBAAmB,OAAO,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAa1C,yBAAyB;AAAA;AAGtB,MAAM,cAAc,OAAO,SAAS;AAAA,EACzC,MAAM;AAAA,EACN,MAAM,oBAAoB;AAC5B,CAAC;AAAA,IACG,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAOV,CAAC,UAAW,MAAM,WAAW,MAAM,MAAM,OAAO,QAAQ,GAAG,IAAI,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAE;AAAA;AAAA;AAAA;AAAA,IAItG,CAAC,EAAE,aAAa,MAAM,gBAAgB,2BAA2B;AAAA;AAAA;AAAA;AAAA;AAAA,IAKjE,CAAC,EAAE,kBAAkB,MACrB,qBACA;AAAA,QACI,0BAA0B;AAAA;AAAA,KAE7B;AAAA;AAGE,MAAM,yBAAyB,OAAO,cAAc;AAAA,EACzD,MAAM;AAAA,EACN,MAAM,oBAAoB;AAC5B,CAAC;AAAA;AAAA,WAEU,CAAC,UAAW,MAAM,kBAAkB,MAAM,MAAM,OAAO,QAAQ,GAAG,IAAI,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAc1G,MAAM,4BAA4B,OAAO;AAAA,IAC5C,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAOd,MAAM,qBAAqB,OAAO,OAAO;AAAA,EAC9C,MAAM;AAAA,EACN,MAAM,oBAAoB;AAC5B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBASsB,CAAC,EAAE,MAAM,MAAM,MAAM,YAAY,KAAK;AAAA;AAAA;AAAA;AAAA;AAMtD,MAAM,kBAAkB,OAAO,KAAK;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { useCallback, useContext } from "react";
|
|
3
|
+
import { isActivationKey } from "@elliemae/ds-props-helpers";
|
|
3
4
|
import { ComboBoxContext } from "../../ComboBoxCTX.js";
|
|
4
5
|
import {
|
|
5
6
|
findInCircularList,
|
|
6
7
|
getOptions,
|
|
7
8
|
getSuggestedValueOnChange,
|
|
8
|
-
getLastValueSelected
|
|
9
|
+
getLastValueSelected,
|
|
10
|
+
isOptionLocked
|
|
9
11
|
} from "../../utils/listHelper.js";
|
|
10
12
|
import { INTERNAL_MENU_OPTION_TYPES, MENU_OPTION_TYPES, MENU_CONTROL_REASONS } from "../../constants.js";
|
|
11
13
|
const isOptionFocuseable = (opt) => !["section", "separator"].includes(opt.type);
|
|
@@ -26,8 +28,6 @@ const useKeyboardNavigation = () => {
|
|
|
26
28
|
selectedValues,
|
|
27
29
|
withoutPortal,
|
|
28
30
|
onlySelectable,
|
|
29
|
-
applyAriaDisabled,
|
|
30
|
-
readOnly,
|
|
31
31
|
isMenuOpenableWithReadOnly
|
|
32
32
|
},
|
|
33
33
|
inputValue,
|
|
@@ -38,7 +38,9 @@ const useKeyboardNavigation = () => {
|
|
|
38
38
|
setMenuState,
|
|
39
39
|
setInputValue,
|
|
40
40
|
scrollOptionIntoView,
|
|
41
|
-
setFocusOptionIdx
|
|
41
|
+
setFocusOptionIdx,
|
|
42
|
+
isInteractionLocked,
|
|
43
|
+
isMenuOpeningLocked
|
|
42
44
|
} = useContext(ComboBoxContext);
|
|
43
45
|
const multiple = Array.isArray(selectedValues);
|
|
44
46
|
const selectableOptions = getOptions(filteredOptions);
|
|
@@ -46,9 +48,11 @@ const useKeyboardNavigation = () => {
|
|
|
46
48
|
const currentItem = filteredOptions.find((item) => item.dsId === focusOptionIdx);
|
|
47
49
|
const onInputKeyDown = useCallback(
|
|
48
50
|
(e) => {
|
|
49
|
-
if (
|
|
50
|
-
if (onKeyDown && currentItem?.type === MENU_OPTION_TYPES.OPTION
|
|
51
|
-
|
|
51
|
+
if (disabled) return;
|
|
52
|
+
if (onKeyDown && currentItem?.type === MENU_OPTION_TYPES.OPTION && !(isInteractionLocked && isActivationKey(e))) {
|
|
53
|
+
onKeyDown(e, currentItem);
|
|
54
|
+
}
|
|
55
|
+
if (["ArrowDown", "ArrowUp", "Enter", "Spacebar"].includes(e.key) && !menuState && !isMenuOpeningLocked) {
|
|
52
56
|
setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);
|
|
53
57
|
}
|
|
54
58
|
if (e.key === "Escape") {
|
|
@@ -59,7 +63,7 @@ const useKeyboardNavigation = () => {
|
|
|
59
63
|
}
|
|
60
64
|
if (!inline) setMenuState(false, MENU_CONTROL_REASONS.CLOSE, e);
|
|
61
65
|
}
|
|
62
|
-
if (!
|
|
66
|
+
if (!isInteractionLocked && e.key === "Enter" && currentItem?.type === INTERNAL_MENU_OPTION_TYPES.CREATABLE && onCreate) {
|
|
63
67
|
e.preventDefault();
|
|
64
68
|
e.stopPropagation();
|
|
65
69
|
onCreate(inputValue);
|
|
@@ -73,8 +77,8 @@ const useKeyboardNavigation = () => {
|
|
|
73
77
|
setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
const isSelectionKey = e.key === "Enter" || e.key === " " && e.altKey || e.key === "Tab" && !multiple && !inline;
|
|
81
|
+
if (isSelectionKey && !isInteractionLocked && !isOptionLocked(currentItem)) {
|
|
78
82
|
if (e.key !== "Tab") e.preventDefault();
|
|
79
83
|
e.stopPropagation();
|
|
80
84
|
if (focusOptionIdx !== "" && (menuState || inline) && currentItem?.type === MENU_OPTION_TYPES.OPTION && !currentItem.disabled) {
|
|
@@ -93,7 +97,7 @@ const useKeyboardNavigation = () => {
|
|
|
93
97
|
if (e.key === "Enter" && e.altKey) {
|
|
94
98
|
setMenuState(false, "selectOption", e);
|
|
95
99
|
}
|
|
96
|
-
if (e.key === "a" && e.ctrlKey && multiple && onSelectAll) {
|
|
100
|
+
if (e.key === "a" && e.ctrlKey && multiple && onSelectAll && !isInteractionLocked) {
|
|
97
101
|
onSelectAll(
|
|
98
102
|
filteredOptions.filter(
|
|
99
103
|
(option) => option.type === "option" && !option.disabled
|
|
@@ -126,7 +130,7 @@ const useKeyboardNavigation = () => {
|
|
|
126
130
|
if (menuState || inline) {
|
|
127
131
|
setFocusOptionIdx(filteredOptions[prevItemIndex].dsId);
|
|
128
132
|
scrollOptionIntoView(filteredOptions[prevItemIndex].dsId);
|
|
129
|
-
} else {
|
|
133
|
+
} else if (!isMenuOpeningLocked) {
|
|
130
134
|
setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);
|
|
131
135
|
const lastItemIndex = findInCircularList(filteredOptions, 0, isOptionFocuseable, -1);
|
|
132
136
|
setFocusOptionIdx(filteredOptions[lastItemIndex].dsId);
|
|
@@ -137,9 +141,9 @@ const useKeyboardNavigation = () => {
|
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
143
|
if (e.key === "Backspace" && e.currentTarget.value.length <= 0 && !inline) {
|
|
140
|
-
if (
|
|
144
|
+
if (isInteractionLocked) return;
|
|
141
145
|
const lastValue = getLastValueSelected(selectedValues);
|
|
142
|
-
if (!e.currentTarget.value && lastValue && !isNonClearable && !lastValue
|
|
146
|
+
if (!e.currentTarget.value && lastValue && !isNonClearable && !isOptionLocked(lastValue)) {
|
|
143
147
|
onChange(
|
|
144
148
|
getSuggestedValueOnChange(lastValue, selectedValues),
|
|
145
149
|
lastValue,
|
|
@@ -151,7 +155,7 @@ const useKeyboardNavigation = () => {
|
|
|
151
155
|
setMenuState(false, MENU_CONTROL_REASONS.BLUR, e);
|
|
152
156
|
}
|
|
153
157
|
if (onlySelectable && /^[a-zA-Z\d]$/.test(e.key)) {
|
|
154
|
-
if (!menuState) {
|
|
158
|
+
if (!menuState && !isMenuOpeningLocked) {
|
|
155
159
|
setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);
|
|
156
160
|
}
|
|
157
161
|
const isOptionFocusableByLetter = (opt) => isOptionFocuseable(opt) && optionHasFirstLetter(opt, e.key);
|
|
@@ -164,6 +168,7 @@ const useKeyboardNavigation = () => {
|
|
|
164
168
|
},
|
|
165
169
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
170
|
[
|
|
171
|
+
disabled,
|
|
167
172
|
onKeyDown,
|
|
168
173
|
currentItem,
|
|
169
174
|
onCreate,
|
|
@@ -184,7 +189,10 @@ const useKeyboardNavigation = () => {
|
|
|
184
189
|
setFocusOptionIdx,
|
|
185
190
|
selectedValues,
|
|
186
191
|
onChange,
|
|
187
|
-
isNonClearable
|
|
192
|
+
isNonClearable,
|
|
193
|
+
isInteractionLocked,
|
|
194
|
+
isMenuOpeningLocked,
|
|
195
|
+
isMenuOpenableWithReadOnly
|
|
188
196
|
]
|
|
189
197
|
);
|
|
190
198
|
return { onInputKeyDown };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/controls-input/useKeyboardNavigation.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext } from 'react';\nimport type { DSComboboxT } from '../../react-desc-prop-types.js';\nimport { ComboBoxContext } from '../../ComboBoxCTX.js';\nimport {\n findInCircularList,\n getOptions,\n getSuggestedValueOnChange,\n getLastValueSelected,\n} from '../../utils/listHelper.js';\nimport type { DSCommonComboboxPropsT } from '../../DSCommonComboboxPropsT.js';\nimport { INTERNAL_MENU_OPTION_TYPES, MENU_OPTION_TYPES, MENU_CONTROL_REASONS } from '../../constants.js';\nconst isOptionFocuseable = (opt: DSComboboxT.OptionTypes): boolean => !['section', 'separator'].includes(opt.type);\n\nconst optionHasFirstLetter = (opt: DSComboboxT.OptionTypes, letter: string): boolean =>\n opt.label !== undefined && opt.label.toLowerCase().startsWith(letter.toLowerCase());\n\nexport const useKeyboardNavigation = () => {\n const {\n props: {\n allOptions,\n isNonClearable,\n onCancel,\n disabled,\n onKeyDown,\n onChange,\n onCreate,\n onFilter,\n onSelectAll,\n inline,\n selectedValues,\n withoutPortal,\n onlySelectable,\n applyAriaDisabled,\n readOnly,\n isMenuOpenableWithReadOnly,\n },\n inputValue,\n correctOptions: filteredOptions,\n menuState,\n focusOptionIdx,\n listRef,\n setMenuState,\n setInputValue,\n scrollOptionIntoView,\n setFocusOptionIdx,\n } = useContext(ComboBoxContext);\n\n const multiple = Array.isArray(selectedValues);\n const selectableOptions = getOptions(filteredOptions);\n const currentItemIndex = filteredOptions.findIndex((opt) => opt.dsId === focusOptionIdx);\n const currentItem = filteredOptions.find((item) => item.dsId === focusOptionIdx);\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (applyAriaDisabled || (readOnly && !isMenuOpenableWithReadOnly) || disabled) return;\n\n // =============================================================================\n // CUSTOM KEYS\n // =============================================================================\n if (onKeyDown && currentItem?.type === MENU_OPTION_TYPES.OPTION) onKeyDown(e, currentItem);\n\n if (['ArrowDown', 'ArrowUp', 'Enter', 'Spacebar'].includes(e.key) && !menuState) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n // =============================================================================\n // ESCAPE\n // =============================================================================\n if (e.key === 'Escape') {\n if (onCancel) onCancel();\n if (inputValue) {\n if (onFilter) onFilter(allOptions, inputValue);\n setInputValue('');\n }\n if (!inline) setMenuState(false, MENU_CONTROL_REASONS.CLOSE, e);\n }\n // =============================================================================\n // ENTER KEY TO CREATE ELEMENTS\n // =============================================================================\n if (!readOnly && e.key === 'Enter' && currentItem?.type === INTERNAL_MENU_OPTION_TYPES.CREATABLE && onCreate) {\n e.preventDefault();\n e.stopPropagation();\n onCreate(inputValue);\n // blank active item to force search last one\n setFocusOptionIdx('');\n if (onFilter) onFilter(allOptions, '');\n setInputValue('');\n return;\n }\n\n // the following code is wrong but kept for backward compatibility to avoid breaking changes\n // when readonly the idea is not to open the menu when typing but currently it opens the menu\n // =============================================================================\n // OPEN MENU ON TYPE WHEN READONLY AND ISMENUOPENABLEWITHREADONLY IS TRUE\n // =============================================================================\n if (isMenuOpenableWithReadOnly && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey) {\n if (!menuState) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n }\n\n // =============================================================================\n // Enter, space and Tab on selection\n // =============================================================================\n if (e.key === 'Enter' || (e.key === ' ' && e.altKey) || (e.key === 'Tab' && !multiple && !inline)) {\n if (readOnly || currentItem?.applyAriaDisabled) return;\n\n if (e.key !== 'Tab') e.preventDefault();\n e.stopPropagation();\n\n if (\n focusOptionIdx !== '' &&\n (menuState || inline) &&\n currentItem?.type === MENU_OPTION_TYPES.OPTION &&\n !currentItem.disabled\n ) {\n if (onFilter) onFilter(allOptions, '');\n setInputValue('');\n if (!multiple) {\n setMenuState(false, MENU_CONTROL_REASONS.SELECT_OPTION, e);\n }\n // DSComboboxT.InternalProps is a conditional type that can't be resolved without an explicit type\n // parameter, so TypeScript treats onChange as a union of functions and requires intersection params.\n // The cast to SelectedOptionsT is safe \u2014 getSuggestedValueOnChange handles both multi/single at runtime.\n (onChange as (v: DSComboboxT.SelectedOptionsT, ...args: unknown[]) => void)(\n getSuggestedValueOnChange(currentItem, selectedValues, isNonClearable),\n currentItem,\n e,\n );\n }\n }\n\n if (e.key === 'Enter' && e.altKey) {\n setMenuState(false, 'selectOption', e);\n }\n\n if (e.key === 'a' && e.ctrlKey && multiple && onSelectAll) {\n onSelectAll(\n filteredOptions.filter(\n (option) => option.type === 'option' && !option.disabled,\n ) as DSCommonComboboxPropsT.SelectionableOptions[],\n e,\n );\n }\n // =============================================================================\n // ARROWS UP AND DOWN: LOGIC TO CALCULATE NEXT OR PREV ITEM TO PSEUDOFOCUS FROM INPUT\n // =============================================================================\n\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n e.stopPropagation();\n if ((menuState || inline) && (selectableOptions.length || onCreate)) {\n const nextItemIndexIndex = findInCircularList(filteredOptions, currentItemIndex, isOptionFocuseable);\n if (nextItemIndexIndex > -1) {\n setFocusOptionIdx(filteredOptions[nextItemIndexIndex].dsId);\n scrollOptionIntoView(filteredOptions[nextItemIndexIndex].dsId);\n }\n }\n }\n if (e.key === 'ArrowUp') {\n e.preventDefault();\n e.stopPropagation();\n if (!selectableOptions.length && !onCreate) return;\n const prevItemIndex = findInCircularList(\n filteredOptions,\n currentItemIndex === -1 ? 0 : currentItemIndex,\n isOptionFocuseable,\n -1,\n );\n if (prevItemIndex > -1) {\n if (menuState || inline) {\n setFocusOptionIdx(filteredOptions[prevItemIndex].dsId);\n scrollOptionIntoView(filteredOptions[prevItemIndex].dsId);\n } else {\n // open menu and search last item to focused\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n const lastItemIndex = findInCircularList(filteredOptions, 0, isOptionFocuseable, -1);\n setFocusOptionIdx(filteredOptions[lastItemIndex].dsId);\n setTimeout(() => {\n scrollOptionIntoView(filteredOptions[lastItemIndex].dsId);\n });\n }\n }\n }\n\n // =============================================================================\n // BACKSPACE\n // =============================================================================\n if (e.key === 'Backspace' && e.currentTarget.value.length <= 0 && !inline) {\n if (readOnly) return;\n const lastValue = getLastValueSelected(selectedValues);\n if (!e.currentTarget.value && lastValue && !isNonClearable && !lastValue.applyAriaDisabled) {\n (onChange as (v: DSComboboxT.SelectedOptionsT, ...args: unknown[]) => void)(\n getSuggestedValueOnChange(lastValue, selectedValues),\n lastValue,\n e,\n );\n }\n }\n\n if (e.key === 'Tab' && !inline && menuState) {\n setMenuState(false, MENU_CONTROL_REASONS.BLUR, e);\n }\n\n // =============================================================================\n // ONLYSELECTABLE LETTER/NUMBER KEYS TO FOCUS OPTIONS\n // =============================================================================\n\n if (onlySelectable && /^[a-zA-Z\\d]$/.test(e.key)) {\n if (!menuState) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n\n const isOptionFocusableByLetter = (opt: DSComboboxT.OptionTypes): boolean =>\n isOptionFocuseable(opt) && optionHasFirstLetter(opt, e.key);\n\n const nextItemIndexIndex = findInCircularList(filteredOptions, currentItemIndex, isOptionFocusableByLetter);\n const nextItem = filteredOptions[nextItemIndexIndex];\n if (!nextItem) return;\n setFocusOptionIdx(filteredOptions[nextItemIndexIndex].dsId);\n scrollOptionIntoView(filteredOptions[nextItemIndexIndex].dsId);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n onKeyDown,\n currentItem,\n onCreate,\n multiple,\n inputValue,\n inline,\n withoutPortal,\n setMenuState,\n onCancel,\n onFilter,\n setInputValue,\n listRef,\n focusOptionIdx,\n menuState,\n selectableOptions.length,\n filteredOptions,\n currentItemIndex,\n setFocusOptionIdx,\n selectedValues,\n onChange,\n isNonClearable,\n ],\n );\n\n return { onInputKeyDown };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext } from 'react';\nimport { isActivationKey } from '@elliemae/ds-props-helpers';\nimport type { DSComboboxT } from '../../react-desc-prop-types.js';\nimport { ComboBoxContext } from '../../ComboBoxCTX.js';\nimport {\n findInCircularList,\n getOptions,\n getSuggestedValueOnChange,\n getLastValueSelected,\n isOptionLocked,\n} from '../../utils/listHelper.js';\nimport type { DSCommonComboboxPropsT } from '../../DSCommonComboboxPropsT.js';\nimport { INTERNAL_MENU_OPTION_TYPES, MENU_OPTION_TYPES, MENU_CONTROL_REASONS } from '../../constants.js';\nconst isOptionFocuseable = (opt: DSComboboxT.OptionTypes): boolean => !['section', 'separator'].includes(opt.type);\n\n// the generic lock rule: the consumer onKeyDown does not receive the activation keys while locked (`isActivationKey`).\n// Every other key, Backspace, Delete and Ctrl+A included, is only observed: the component's own removal and select-all\n// are gated below.\n\nconst optionHasFirstLetter = (opt: DSComboboxT.OptionTypes, letter: string): boolean =>\n opt.label !== undefined && opt.label.toLowerCase().startsWith(letter.toLowerCase());\n\nexport const useKeyboardNavigation = () => {\n const {\n props: {\n allOptions,\n isNonClearable,\n onCancel,\n disabled,\n onKeyDown,\n onChange,\n onCreate,\n onFilter,\n onSelectAll,\n inline,\n selectedValues,\n withoutPortal,\n onlySelectable,\n isMenuOpenableWithReadOnly,\n },\n inputValue,\n correctOptions: filteredOptions,\n menuState,\n focusOptionIdx,\n listRef,\n setMenuState,\n setInputValue,\n scrollOptionIntoView,\n setFocusOptionIdx,\n isInteractionLocked,\n isMenuOpeningLocked,\n } = useContext(ComboBoxContext);\n\n const multiple = Array.isArray(selectedValues);\n const selectableOptions = getOptions(filteredOptions);\n const currentItemIndex = filteredOptions.findIndex((opt) => opt.dsId === focusOptionIdx);\n const currentItem = filteredOptions.find((item) => item.dsId === focusOptionIdx);\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n // disabled blocks every key. applyAriaDisabled and readOnly keep focus and navigation (arrows, Tab, Escape)\n // and block every key that opens an option or changes the value (PUI-16695). They block the keys that open the\n // menu too, unless isMenuOpenableWithReadOnly is set: then the arrows, Enter and Space open it to be read.\n if (disabled) return;\n\n // =============================================================================\n // CUSTOM KEYS\n // =============================================================================\n if (onKeyDown && currentItem?.type === MENU_OPTION_TYPES.OPTION && !(isInteractionLocked && isActivationKey(e))) {\n onKeyDown(e, currentItem);\n }\n\n if (['ArrowDown', 'ArrowUp', 'Enter', 'Spacebar'].includes(e.key) && !menuState && !isMenuOpeningLocked) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n // =============================================================================\n // ESCAPE\n // =============================================================================\n if (e.key === 'Escape') {\n if (onCancel) onCancel();\n if (inputValue) {\n if (onFilter) onFilter(allOptions, inputValue);\n setInputValue('');\n }\n if (!inline) setMenuState(false, MENU_CONTROL_REASONS.CLOSE, e);\n }\n // =============================================================================\n // ENTER KEY TO CREATE ELEMENTS\n // =============================================================================\n if (\n !isInteractionLocked &&\n e.key === 'Enter' &&\n currentItem?.type === INTERNAL_MENU_OPTION_TYPES.CREATABLE &&\n onCreate\n ) {\n e.preventDefault();\n e.stopPropagation();\n onCreate(inputValue);\n // blank active item to force search last one\n setFocusOptionIdx('');\n if (onFilter) onFilter(allOptions, '');\n setInputValue('');\n return;\n }\n\n // under a soft lock (applyAriaDisabled or readOnly) typing opens the menu only when the consumer opts in with\n // isMenuOpenableWithReadOnly: opening is view-only, what the menu holds stays locked\n // =============================================================================\n // OPEN MENU ON TYPE WHEN READONLY AND ISMENUOPENABLEWITHREADONLY IS TRUE\n // =============================================================================\n if (isMenuOpenableWithReadOnly && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey) {\n if (!menuState) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n }\n\n // =============================================================================\n // Enter, space and Tab on selection\n // =============================================================================\n const isSelectionKey =\n e.key === 'Enter' || (e.key === ' ' && e.altKey) || (e.key === 'Tab' && !multiple && !inline);\n if (isSelectionKey && !isInteractionLocked && !isOptionLocked(currentItem)) {\n if (e.key !== 'Tab') e.preventDefault();\n e.stopPropagation();\n\n if (\n focusOptionIdx !== '' &&\n (menuState || inline) &&\n currentItem?.type === MENU_OPTION_TYPES.OPTION &&\n !currentItem.disabled\n ) {\n if (onFilter) onFilter(allOptions, '');\n setInputValue('');\n if (!multiple) {\n setMenuState(false, MENU_CONTROL_REASONS.SELECT_OPTION, e);\n }\n // DSComboboxT.InternalProps is a conditional type that can't be resolved without an explicit type\n // parameter, so TypeScript treats onChange as a union of functions and requires intersection params.\n // The cast to SelectedOptionsT is safe \u2014 getSuggestedValueOnChange handles both multi/single at runtime.\n (onChange as (v: DSComboboxT.SelectedOptionsT, ...args: unknown[]) => void)(\n getSuggestedValueOnChange(currentItem, selectedValues, isNonClearable),\n currentItem,\n e,\n );\n }\n }\n\n if (e.key === 'Enter' && e.altKey) {\n setMenuState(false, 'selectOption', e);\n }\n\n if (e.key === 'a' && e.ctrlKey && multiple && onSelectAll && !isInteractionLocked) {\n onSelectAll(\n filteredOptions.filter(\n (option) => option.type === 'option' && !option.disabled,\n ) as DSCommonComboboxPropsT.SelectionableOptions[],\n e,\n );\n }\n // =============================================================================\n // ARROWS UP AND DOWN: LOGIC TO CALCULATE NEXT OR PREV ITEM TO PSEUDOFOCUS FROM INPUT\n // =============================================================================\n\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n e.stopPropagation();\n if ((menuState || inline) && (selectableOptions.length || onCreate)) {\n const nextItemIndexIndex = findInCircularList(filteredOptions, currentItemIndex, isOptionFocuseable);\n if (nextItemIndexIndex > -1) {\n setFocusOptionIdx(filteredOptions[nextItemIndexIndex].dsId);\n scrollOptionIntoView(filteredOptions[nextItemIndexIndex].dsId);\n }\n }\n }\n if (e.key === 'ArrowUp') {\n e.preventDefault();\n e.stopPropagation();\n if (!selectableOptions.length && !onCreate) return;\n const prevItemIndex = findInCircularList(\n filteredOptions,\n currentItemIndex === -1 ? 0 : currentItemIndex,\n isOptionFocuseable,\n -1,\n );\n if (prevItemIndex > -1) {\n if (menuState || inline) {\n setFocusOptionIdx(filteredOptions[prevItemIndex].dsId);\n scrollOptionIntoView(filteredOptions[prevItemIndex].dsId);\n } else if (!isMenuOpeningLocked) {\n // open menu and search last item to focused\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n const lastItemIndex = findInCircularList(filteredOptions, 0, isOptionFocuseable, -1);\n setFocusOptionIdx(filteredOptions[lastItemIndex].dsId);\n setTimeout(() => {\n scrollOptionIntoView(filteredOptions[lastItemIndex].dsId);\n });\n }\n }\n }\n\n // =============================================================================\n // BACKSPACE\n // =============================================================================\n if (e.key === 'Backspace' && e.currentTarget.value.length <= 0 && !inline) {\n if (isInteractionLocked) return;\n const lastValue = getLastValueSelected(selectedValues);\n if (!e.currentTarget.value && lastValue && !isNonClearable && !isOptionLocked(lastValue)) {\n (onChange as (v: DSComboboxT.SelectedOptionsT, ...args: unknown[]) => void)(\n getSuggestedValueOnChange(lastValue, selectedValues),\n lastValue,\n e,\n );\n }\n }\n\n if (e.key === 'Tab' && !inline && menuState) {\n setMenuState(false, MENU_CONTROL_REASONS.BLUR, e);\n }\n\n // =============================================================================\n // ONLYSELECTABLE LETTER/NUMBER KEYS TO FOCUS OPTIONS\n // =============================================================================\n\n if (onlySelectable && /^[a-zA-Z\\d]$/.test(e.key)) {\n if (!menuState && !isMenuOpeningLocked) {\n setMenuState(true, MENU_CONTROL_REASONS.OPEN, e);\n }\n\n const isOptionFocusableByLetter = (opt: DSComboboxT.OptionTypes): boolean =>\n isOptionFocuseable(opt) && optionHasFirstLetter(opt, e.key);\n\n const nextItemIndexIndex = findInCircularList(filteredOptions, currentItemIndex, isOptionFocusableByLetter);\n const nextItem = filteredOptions[nextItemIndexIndex];\n if (!nextItem) return;\n setFocusOptionIdx(filteredOptions[nextItemIndexIndex].dsId);\n scrollOptionIntoView(filteredOptions[nextItemIndexIndex].dsId);\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n disabled,\n onKeyDown,\n currentItem,\n onCreate,\n multiple,\n inputValue,\n inline,\n withoutPortal,\n setMenuState,\n onCancel,\n onFilter,\n setInputValue,\n listRef,\n focusOptionIdx,\n menuState,\n selectableOptions.length,\n filteredOptions,\n currentItemIndex,\n setFocusOptionIdx,\n selectedValues,\n onChange,\n isNonClearable,\n isInteractionLocked,\n isMenuOpeningLocked,\n isMenuOpenableWithReadOnly,\n ],\n );\n\n return { onInputKeyDown };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,kBAAkB;AACxC,SAAS,uBAAuB;AAEhC,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,4BAA4B,mBAAmB,4BAA4B;AACpF,MAAM,qBAAqB,CAAC,QAA0C,CAAC,CAAC,WAAW,WAAW,EAAE,SAAS,IAAI,IAAI;AAMjH,MAAM,uBAAuB,CAAC,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F;AAEA,UAAI,EAAE,QAAQ,SAAS,CAAC,UAAU,WAAW;AAC3C,qBAAa,OAAO,qBAAqB,MAAM,CAAC;AAAA,MAClD;AAMA,UAAI,kBAAkB,eAAe,KAAK,EAAE,GAAG,GAAG;AAChD,YAAI,CAAC,aAAa,CAAC,qBAAqB;AACtC,uBAAa,MAAM,qBAAqB,MAAM,CAAC;AAAA,QACjD;AAEA,cAAM,4BAA4B,CAAC,QACjC,mBAAmB,GAAG,KAAK,qBAAqB,KAAK,EAAE,GAAG;AAE5D,cAAM,qBAAqB,mBAAmB,iBAAiB,kBAAkB,yBAAyB;AAC1G,cAAM,WAAW,gBAAgB,kBAAkB;AACnD,YAAI,CAAC,SAAU;AACf,0BAAkB,gBAAgB,kBAAkB,EAAE,IAAI;AAC1D,6BAAqB,gBAAgB,kBAAkB,EAAE,IAAI;AAAA,MAC/D;AAAA,IACF;AAAA;AAAA,IAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,eAAe;AAC1B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,14 +4,14 @@ import ComboBoxContext from "../../ComboBoxCTX.js";
|
|
|
4
4
|
import { filterOptions } from "../../utils/listHelper.js";
|
|
5
5
|
const useMaskedOnChange = () => {
|
|
6
6
|
const {
|
|
7
|
-
props: { useMask, onFilter, allOptions
|
|
7
|
+
props: { useMask, onFilter, allOptions },
|
|
8
|
+
isInteractionLocked,
|
|
8
9
|
setMenuState,
|
|
9
10
|
setInputValue,
|
|
10
11
|
setFocusOptionIdx
|
|
11
12
|
} = useContext(ComboBoxContext);
|
|
12
13
|
const handleOnChange = useCallback(
|
|
13
14
|
(e) => {
|
|
14
|
-
if (applyAriaDisabled) return;
|
|
15
15
|
setMenuState(true, "filter", e);
|
|
16
16
|
if (onFilter) {
|
|
17
17
|
onFilter(filterOptions(e.currentTarget.value, allOptions), e.currentTarget.value);
|
|
@@ -19,7 +19,7 @@ const useMaskedOnChange = () => {
|
|
|
19
19
|
setFocusOptionIdx("");
|
|
20
20
|
setInputValue(e.currentTarget.value);
|
|
21
21
|
},
|
|
22
|
-
[
|
|
22
|
+
[setMenuState, onFilter, setFocusOptionIdx, setInputValue, allOptions]
|
|
23
23
|
);
|
|
24
24
|
const handleOnChangeMask = useCallback(
|
|
25
25
|
(e, mask) => {
|
|
@@ -30,7 +30,14 @@ const useMaskedOnChange = () => {
|
|
|
30
30
|
[setMenuState, onFilter, allOptions]
|
|
31
31
|
);
|
|
32
32
|
const onChangeMask = useMask?.({ valueSetter: setInputValue, onChange: handleOnChangeMask });
|
|
33
|
-
|
|
33
|
+
const changeHandler = onChangeMask?.onChange || handleOnChange;
|
|
34
|
+
return useCallback(
|
|
35
|
+
(e) => {
|
|
36
|
+
if (isInteractionLocked) return;
|
|
37
|
+
changeHandler(e);
|
|
38
|
+
},
|
|
39
|
+
[isInteractionLocked, changeHandler]
|
|
40
|
+
);
|
|
34
41
|
};
|
|
35
42
|
export {
|
|
36
43
|
useMaskedOnChange
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/controls-input/useMaskedOnChange.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useContext, useCallback } from 'react';\nimport ComboBoxContext from '../../ComboBoxCTX.js';\nimport { filterOptions } from '../../utils/listHelper.js';\n\nconst useMaskedOnChange = () => {\n const {\n props: { useMask, onFilter, allOptions
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,YAAY,mBAAmB;AACxC,OAAO,qBAAqB;AAC5B,SAAS,qBAAqB;AAE9B,MAAM,oBAAoB,MAAM;AAC9B,QAAM;AAAA,IACJ,OAAO,EAAE,SAAS,UAAU,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useContext, useCallback } from 'react';\nimport ComboBoxContext from '../../ComboBoxCTX.js';\nimport { filterOptions } from '../../utils/listHelper.js';\n\nconst useMaskedOnChange = () => {\n const {\n props: { useMask, onFilter, allOptions },\n isInteractionLocked,\n setMenuState,\n setInputValue,\n setFocusOptionIdx,\n } = useContext(ComboBoxContext);\n\n // default onchange when no mask provided\n const handleOnChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n setMenuState(true, 'filter', e);\n if (onFilter) {\n // when filtering is controlled we suggest the basic filtering but let the user decide\n onFilter(filterOptions(e.currentTarget.value, allOptions), e.currentTarget.value);\n }\n setFocusOptionIdx('');\n setInputValue(e.currentTarget.value);\n },\n [setMenuState, onFilter, setFocusOptionIdx, setInputValue, allOptions],\n );\n\n // onchange used when mask is provided\n const handleOnChangeMask = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, mask?: string) => {\n setMenuState(true, 'filter', e);\n if (mask && onFilter) onFilter(filterOptions(mask, allOptions), mask);\n else if (!mask && onFilter) onFilter(allOptions, '');\n },\n [setMenuState, onFilter, allOptions],\n );\n\n const onChangeMask = useMask?.({ valueSetter: setInputValue, onChange: handleOnChangeMask });\n const changeHandler = onChangeMask?.onChange || handleOnChange;\n\n // PUI-16695: while disabled, applyAriaDisabled or readOnly no change reaches the input, the mask included.\n // The mask hook writes through its own valueSetter, so the guard has to sit in front of it.\n return useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n if (isInteractionLocked) return;\n changeHandler(e);\n },\n [isInteractionLocked, changeHandler],\n );\n};\n\nexport { useMaskedOnChange };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,YAAY,mBAAmB;AACxC,OAAO,qBAAqB;AAC5B,SAAS,qBAAqB;AAE9B,MAAM,oBAAoB,MAAM;AAC9B,QAAM;AAAA,IACJ,OAAO,EAAE,SAAS,UAAU,WAAW;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,eAAe;AAG9B,QAAM,iBAAiB;AAAA,IACrB,CAAC,MAA2C;AAC1C,mBAAa,MAAM,UAAU,CAAC;AAC9B,UAAI,UAAU;AAEZ,iBAAS,cAAc,EAAE,cAAc,OAAO,UAAU,GAAG,EAAE,cAAc,KAAK;AAAA,MAClF;AACA,wBAAkB,EAAE;AACpB,oBAAc,EAAE,cAAc,KAAK;AAAA,IACrC;AAAA,IACA,CAAC,cAAc,UAAU,mBAAmB,eAAe,UAAU;AAAA,EACvE;AAGA,QAAM,qBAAqB;AAAA,IACzB,CAAC,GAAwC,SAAkB;AACzD,mBAAa,MAAM,UAAU,CAAC;AAC9B,UAAI,QAAQ,SAAU,UAAS,cAAc,MAAM,UAAU,GAAG,IAAI;AAAA,eAC3D,CAAC,QAAQ,SAAU,UAAS,YAAY,EAAE;AAAA,IACrD;AAAA,IACA,CAAC,cAAc,UAAU,UAAU;AAAA,EACrC;AAEA,QAAM,eAAe,UAAU,EAAE,aAAa,eAAe,UAAU,mBAAmB,CAAC;AAC3F,QAAM,gBAAgB,cAAc,YAAY;AAIhD,SAAO;AAAA,IACL,CAAC,MAA2C;AAC1C,UAAI,oBAAqB;AACzB,oBAAc,CAAC;AAAA,IACjB;AAAA,IACA,CAAC,qBAAqB,aAAa;AAAA,EACrC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,23 +3,24 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useMemo, useContext, useCallback } from "react";
|
|
4
4
|
import { Grid } from "@elliemae/ds-grid";
|
|
5
5
|
import { Separator } from "@elliemae/ds-menu-items";
|
|
6
|
-
import { useOwnerProps } from "@elliemae/ds-props-helpers";
|
|
6
|
+
import { omitLockedHandlers, useOwnerProps } from "@elliemae/ds-props-helpers";
|
|
7
7
|
import { Section } from "../Section.js";
|
|
8
8
|
import { ComboBoxContext } from "../../ComboBoxCTX.js";
|
|
9
9
|
import { StyledCreatableLabel, StyledCreatableValue, StyledSingleMenuItem, StyledMultiMenuItem } from "./styled.js";
|
|
10
|
-
import { isSelected, getSuggestedValueOnChange } from "../../utils/listHelper.js";
|
|
10
|
+
import { isSelected, getSuggestedValueOnChange, isOptionLocked } from "../../utils/listHelper.js";
|
|
11
11
|
import { ComboboxDataTestid } from "../../ComboboxDataTestids.js";
|
|
12
12
|
import { MENU_OPTION_TYPES, INTERNAL_MENU_OPTION_TYPES } from "../../constants.js";
|
|
13
13
|
const ItemRenderer = ({ index, extraItemProps }) => {
|
|
14
14
|
const {
|
|
15
15
|
props,
|
|
16
|
-
props: { onCreate, onChange, isNonClearable, selectedValues, onFilter, allOptions
|
|
16
|
+
props: { onCreate, onChange, isNonClearable, selectedValues, onFilter, allOptions },
|
|
17
17
|
setMenuState,
|
|
18
18
|
inputValue,
|
|
19
19
|
focusOptionIdx,
|
|
20
20
|
setInputValue,
|
|
21
21
|
setFocusOptionIdx,
|
|
22
|
-
optionsPerSection
|
|
22
|
+
optionsPerSection,
|
|
23
|
+
isInteractionLocked
|
|
23
24
|
} = useContext(ComboBoxContext);
|
|
24
25
|
const { getOwnerProps } = useOwnerProps(props);
|
|
25
26
|
const getOwnerPropsArguments = useCallback(
|
|
@@ -32,16 +33,17 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
32
33
|
const multiple = Array.isArray(selectedValues);
|
|
33
34
|
const CBItem = multiple ? StyledMultiMenuItem : StyledSingleMenuItem;
|
|
34
35
|
const handleOnCreateClick = useCallback(() => {
|
|
36
|
+
if (isInteractionLocked) return;
|
|
35
37
|
if (inputValue && onCreate) {
|
|
36
38
|
onCreate(inputValue);
|
|
37
39
|
setFocusOptionIdx("");
|
|
38
40
|
setInputValue("");
|
|
39
41
|
if (onFilter) onFilter(allOptions, "");
|
|
40
42
|
}
|
|
41
|
-
}, [onFilter, onCreate, inputValue, allOptions, setInputValue, setFocusOptionIdx]);
|
|
43
|
+
}, [isInteractionLocked, onFilter, onCreate, inputValue, allOptions, setInputValue, setFocusOptionIdx]);
|
|
42
44
|
const handleClick = useCallback(
|
|
43
45
|
(currentOption, e) => {
|
|
44
|
-
if (
|
|
46
|
+
if (isInteractionLocked || isOptionLocked(currentOption)) return;
|
|
45
47
|
if (currentOption.type === MENU_OPTION_TYPES.OPTION) {
|
|
46
48
|
if (!currentOption.disabled) {
|
|
47
49
|
if (onFilter) onFilter(allOptions, inputValue);
|
|
@@ -59,7 +61,7 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
59
61
|
e.stopPropagation();
|
|
60
62
|
e.preventDefault();
|
|
61
63
|
},
|
|
62
|
-
[onFilter, selectedValues, allOptions, onChange, setMenuState, multiple]
|
|
64
|
+
[isInteractionLocked, onFilter, selectedValues, allOptions, onChange, setMenuState, multiple]
|
|
63
65
|
);
|
|
64
66
|
const handleOnMouseDown = useCallback((e) => {
|
|
65
67
|
e.preventDefault();
|
|
@@ -67,12 +69,17 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
67
69
|
return useMemo(() => {
|
|
68
70
|
if (option) {
|
|
69
71
|
const { dsId, type, disabled, applyAriaDisabled, readOnly: itemReadOnly, ...rest } = option;
|
|
72
|
+
const {
|
|
73
|
+
onClick: consumerOnClick,
|
|
74
|
+
onMouseDown: consumerOnMouseDown,
|
|
75
|
+
...restHandlers
|
|
76
|
+
} = omitLockedHandlers(rest, Boolean(isInteractionLocked || disabled || applyAriaDisabled || itemReadOnly));
|
|
70
77
|
const generalProps = {
|
|
71
78
|
// 'aria-setsize': `${allOptions.length}`,
|
|
72
79
|
// 'aria-posinset': `${vItem.index + 1}`,
|
|
73
80
|
key: `${dsId}`,
|
|
74
81
|
dsId: dsId.toString(),
|
|
75
|
-
...
|
|
82
|
+
...restHandlers
|
|
76
83
|
};
|
|
77
84
|
if (option.type === MENU_OPTION_TYPES.SECTION) {
|
|
78
85
|
return /* @__PURE__ */ jsx(
|
|
@@ -86,7 +93,8 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
86
93
|
handleOnMouseDown,
|
|
87
94
|
selectedValues,
|
|
88
95
|
getOwnerProps,
|
|
89
|
-
getOwnerPropsArguments
|
|
96
|
+
getOwnerPropsArguments,
|
|
97
|
+
isInteractionLocked
|
|
90
98
|
}
|
|
91
99
|
);
|
|
92
100
|
}
|
|
@@ -102,12 +110,15 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
102
110
|
label: option.label,
|
|
103
111
|
dataTestid: ComboboxDataTestid.OPTION,
|
|
104
112
|
disabled,
|
|
105
|
-
applyAriaDisabled: applyAriaDisabled || itemReadOnly,
|
|
113
|
+
applyAriaDisabled: Boolean(applyAriaDisabled || itemReadOnly || isInteractionLocked),
|
|
106
114
|
onClick: (e) => {
|
|
107
|
-
|
|
115
|
+
consumerOnClick?.(e);
|
|
108
116
|
handleClick(option, e);
|
|
109
117
|
},
|
|
110
|
-
onMouseDown:
|
|
118
|
+
onMouseDown: (e) => {
|
|
119
|
+
consumerOnMouseDown?.(e);
|
|
120
|
+
handleOnMouseDown(e);
|
|
121
|
+
},
|
|
111
122
|
isActive: dsId === focusOptionIdx,
|
|
112
123
|
tabIndex: -1,
|
|
113
124
|
isSelected: isSelected(selectedValues, option),
|
|
@@ -138,7 +149,7 @@ const ItemRenderer = ({ index, extraItemProps }) => {
|
|
|
138
149
|
return null;
|
|
139
150
|
}
|
|
140
151
|
return null;
|
|
141
|
-
}, [optionsPerSection, focusOptionIdx, selectedValues, allOptions, onCreate, inputValue,
|
|
152
|
+
}, [optionsPerSection, focusOptionIdx, selectedValues, allOptions, onCreate, inputValue, isInteractionLocked]);
|
|
142
153
|
};
|
|
143
154
|
export {
|
|
144
155
|
ItemRenderer
|