@primer/react 0.0.0-20260626210038 → 0.0.0-20260626214459
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteInput.d.ts","sourceRoot":"","sources":["../../src/Autocomplete/AutocompleteInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqD,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAE/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAGlD,KAAK,8BAA8B,GAAG;IAEpC,EAAE,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAEtD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAID,QAAA,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"AutocompleteInput.d.ts","sourceRoot":"","sources":["../../src/Autocomplete/AutocompleteInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAqD,MAAM,OAAO,CAAA;AACzE,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAE/F,OAAO,SAAS,MAAM,cAAc,CAAA;AAEpC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAA;AAGlD,KAAK,8BAA8B,GAAG;IAEpC,EAAE,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAEtD;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAID,QAAA,MAAM,iBAAiB,EA0KlB,8BAA8B,CAAC,OAAO,SAAS,EAAE,8BAA8B,CAAC,CAAA;AAIrF,MAAM,MAAM,sBAAsB,GAAG,cAAc,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAC7E,eAAe,iBAAiB,CAAA"}
|
|
@@ -48,13 +48,15 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
const handleInputBlur = useCallback(event => {
|
|
51
|
-
onBlur
|
|
51
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
52
52
|
|
|
53
|
-
// HACK: wait a tick
|
|
54
|
-
//
|
|
55
|
-
//
|
|
53
|
+
// HACK: wait a tick before hiding the menu so click interactions can complete.
|
|
54
|
+
// Use the blur event's relatedTarget to determine whether focus is moving into the
|
|
55
|
+
// autocomplete menu; if not, hide the menu when focus leaves the input.
|
|
56
56
|
safeSetTimeout(() => {
|
|
57
|
-
|
|
57
|
+
const nextFocusedElement = event.relatedTarget;
|
|
58
|
+
const menuElement = document.getElementById(`${id}-listbox`);
|
|
59
|
+
if (!nextFocusedElement || nextFocusedElement !== menuElement && !(menuElement !== null && menuElement !== void 0 && menuElement.contains(nextFocusedElement))) {
|
|
58
60
|
setShowMenu(false);
|
|
59
61
|
|
|
60
62
|
// Reset the input's value to the text the user actually typed rather than leaving the
|
|
@@ -66,9 +68,9 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}, 0);
|
|
69
|
-
}, [onBlur, setShowMenu, inputRef, safeSetTimeout, autocompleteSuggestion, inputValue]);
|
|
71
|
+
}, [onBlur, setShowMenu, inputRef, safeSetTimeout, autocompleteSuggestion, inputValue, id]);
|
|
70
72
|
const handleInputChange = event => {
|
|
71
|
-
onChange
|
|
73
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
72
74
|
setInputValue(event.currentTarget.value);
|
|
73
75
|
if (!showMenu) {
|
|
74
76
|
setShowMenu(true);
|
|
@@ -76,7 +78,7 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
76
78
|
};
|
|
77
79
|
const handleInputKeyDown = useCallback(event => {
|
|
78
80
|
var _inputRef$current;
|
|
79
|
-
onKeyDown
|
|
81
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
80
82
|
if (event.key === 'Backspace') {
|
|
81
83
|
setHighlightRemainingText(false);
|
|
82
84
|
}
|
|
@@ -89,18 +91,16 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
89
91
|
}
|
|
90
92
|
}, [inputRef, setInputValue, setHighlightRemainingText, onKeyDown, showMenu, setShowMenu]);
|
|
91
93
|
const handleInputKeyUp = useCallback(event => {
|
|
92
|
-
onKeyUp
|
|
94
|
+
onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(event);
|
|
93
95
|
if (event.key === 'Backspace') {
|
|
94
96
|
setHighlightRemainingText(true);
|
|
95
97
|
}
|
|
96
98
|
}, [setHighlightRemainingText, onKeyUp]);
|
|
97
99
|
const onInputKeyPress = useCallback(event => {
|
|
98
|
-
onKeyPress
|
|
100
|
+
onKeyPress === null || onKeyPress === void 0 ? void 0 : onKeyPress(event);
|
|
99
101
|
if (showMenu && event.key === 'Enter' && activeDescendantRef.current) {
|
|
100
102
|
event.preventDefault();
|
|
101
103
|
event.nativeEvent.stopImmediatePropagation();
|
|
102
|
-
|
|
103
|
-
// Forward Enter key press to active descendant so that item gets activated
|
|
104
104
|
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
|
105
105
|
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
|
106
106
|
}
|
|
@@ -109,18 +109,9 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
109
109
|
if (!inputRef.current) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
// resets input value to being empty after a selection has been made
|
|
114
112
|
if (!autocompleteSuggestion) {
|
|
115
113
|
inputRef.current.value = inputValue;
|
|
116
114
|
}
|
|
117
|
-
|
|
118
|
-
// TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
|
|
119
|
-
// is the same as what I'm typing
|
|
120
|
-
// e.g.: typing 'tw' highlights 'two', but when I 'two', the text input change does not get triggered
|
|
121
|
-
// Only apply the inline autocomplete suggestion while the input is focused. Without this guard,
|
|
122
|
-
// the suggestion can be re-applied to the DOM after the input is blurred, which would restore
|
|
123
|
-
// the full suggestion the user was editing away from. See https://github.com/primer/react/issues/4275
|
|
124
115
|
const isInputFocused = document.activeElement === inputRef.current;
|
|
125
116
|
if (isInputFocused &&
|
|
126
117
|
// eslint-disable-next-line react-you-might-not-need-an-effect/no-event-handler
|
|
@@ -131,7 +122,6 @@ const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
|
|
|
131
122
|
}
|
|
132
123
|
}
|
|
133
124
|
|
|
134
|
-
// calling this useEffect when `highlightRemainingText` changes breaks backspace functionality
|
|
135
125
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
126
|
}, [autocompleteSuggestion, inputValue, inputRef, isMenuDirectlyActivated]);
|
|
137
127
|
useEffect(() => {
|
package/package.json
CHANGED