@primer/react 0.0.0-20260626204956 → 0.0.0-20260626214211
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 +1 -1
- package/dist/Autocomplete/AutocompleteInput.d.ts.map +1 -1
- package/dist/Autocomplete/AutocompleteInput.js +13 -25
- package/dist/FilteredActionList/FilteredActionList.js +2 -2
- package/dist/FilteredActionList/FilteredActionListInput.d.ts +1 -1
- package/dist/FilteredActionList/FilteredActionListInput.d.ts.map +1 -1
- package/package.json +1 -1
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,EAyKlB,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,29 +109,17 @@ 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
|
-
if (isInputFocused &&
|
|
126
|
-
// eslint-disable-next-line react-you-might-not-need-an-effect/no-event-handler
|
|
127
|
-
highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
|
116
|
+
if (isInputFocused && highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
|
128
117
|
inputRef.current.value = autocompleteSuggestion;
|
|
129
118
|
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
|
130
119
|
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
|
131
120
|
}
|
|
132
121
|
}
|
|
133
122
|
|
|
134
|
-
// calling this useEffect when `highlightRemainingText` changes breaks backspace functionality
|
|
135
123
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
136
124
|
}, [autocompleteSuggestion, inputValue, inputRef, isMenuDirectlyActivated]);
|
|
137
125
|
useEffect(() => {
|
|
@@ -77,7 +77,7 @@ function FilteredActionList({
|
|
|
77
77
|
const scrollContainerRef = useRef(null);
|
|
78
78
|
const combinedScrollContainerRef = useMergedRefs(scrollContainerRef, providedScrollContainerRef);
|
|
79
79
|
const inputRef = useRef(null);
|
|
80
|
-
useMergedRefs(inputRef, providedInputRef);
|
|
80
|
+
const combinedInputRef = useMergedRefs(inputRef, providedInputRef);
|
|
81
81
|
const usingRovingTabindex = _PrivateFocusManagement === 'roving-tabindex';
|
|
82
82
|
const [listContainerElement, setListContainerElement] = useState(null);
|
|
83
83
|
const activeDescendantRef = useRef();
|
|
@@ -396,7 +396,7 @@ function FilteredActionList({
|
|
|
396
396
|
"data-testid": "filtered-action-list",
|
|
397
397
|
"data-component": "FilteredActionList",
|
|
398
398
|
children: [/*#__PURE__*/jsx(FilteredActionListInput, {
|
|
399
|
-
inputRef:
|
|
399
|
+
inputRef: combinedInputRef,
|
|
400
400
|
value: filterValue,
|
|
401
401
|
onInputChange: onInputChange,
|
|
402
402
|
onInputKeyPress: onInputKeyPress,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { TextInputProps } from '../TextInput';
|
|
3
3
|
export interface FilteredActionListInputProps extends Partial<Omit<TextInputProps, 'onChange' | 'onKeyDown'>> {
|
|
4
|
-
inputRef: React.
|
|
4
|
+
inputRef: React.Ref<HTMLInputElement | null>;
|
|
5
5
|
onInputChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
6
6
|
onInputKeyPress?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
7
7
|
onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteredActionListInput.d.ts","sourceRoot":"","sources":["../../src/FilteredActionList/FilteredActionListInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,cAAc,CAAA;AAGhD,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;IAC3G,QAAQ,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"FilteredActionListInput.d.ts","sourceRoot":"","sources":["../../src/FilteredActionList/FilteredActionListInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,cAAc,CAAA;AAGhD,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;IAC3G,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAA;IAC5C,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAA;IAChE,eAAe,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAC9D,cAAc,CAAC,EAAE,KAAK,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,sBAAsB,EAAE,MAAM,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,EACtC,QAAQ,EACR,KAAK,EACL,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,EACf,MAAM,EACN,sBAAsB,EACtB,OAAO,EACP,kBAAkB,EAClB,SAAS,EACT,GAAG,kBAAkB,EACtB,EAAE,4BAA4B,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA2BlD"}
|
package/package.json
CHANGED