@acusti/dropdown 1.1.0 → 1.1.1
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/README.md +19 -6
- package/dist/Dropdown.d.ts +2 -1
- package/dist/Dropdown.js +5 -2
- package/dist/Dropdown.js.map +1 -1
- package/dist/helpers.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -325,7 +325,8 @@ type Props = {
|
|
|
325
325
|
* multi-select. Defaults to !hasItems: a menu closes on submit, while a
|
|
326
326
|
* hasItems={false} dialog stays open. In a hasItems={false} dropdown, a
|
|
327
327
|
* submit is a form in the body being submitted, or Enter in a
|
|
328
|
-
* single-line input
|
|
328
|
+
* single-line input that appears in the body with no form or in the
|
|
329
|
+
* trigger.
|
|
329
330
|
*/
|
|
330
331
|
keepOpenOnSubmit?: boolean;
|
|
331
332
|
/**
|
|
@@ -726,12 +727,17 @@ while it’s open, as when it opened on hover. Escape closes the dropdown
|
|
|
726
727
|
unless focus is in a text field (a text input, a textarea, or an editable
|
|
727
728
|
element). On the trigger, Space and Enter open the dropdown and, unless
|
|
728
729
|
focus is in a text field or a checkbox there, close it again, as a click
|
|
729
|
-
there does.
|
|
730
|
+
there does. Once it is open, Enter in a textarea or an editable element
|
|
731
|
+
used as the trigger adds a line break there. Enter in a single-line input
|
|
732
|
+
used as the trigger is a submit, whether or not a form owns it: the
|
|
733
|
+
dropdown takes the key, so a form around the trigger isn’t submitted from
|
|
734
|
+
that input while the dropdown is open.
|
|
730
735
|
|
|
731
736
|
A `hasItems={false}` dropdown stays open until it is dismissed. Pass
|
|
732
737
|
`keepOpenOnSubmit={false}` to close it when its content is submitted. A
|
|
733
738
|
submit is a form in the body being submitted, by Enter in one of its inputs
|
|
734
|
-
or by its submit button, or Enter in a single-line input
|
|
739
|
+
or by its submit button, or Enter in a single-line input, either one in the
|
|
740
|
+
body that no form owns or one used as the trigger:
|
|
735
741
|
|
|
736
742
|
```tsx
|
|
737
743
|
<Dropdown hasItems={false} keepOpenOnSubmit={false}>
|
|
@@ -753,9 +759,9 @@ empty. To keep it open after a submit that your own checks reject, call
|
|
|
753
759
|
check that finishes later, such as a server round trip or a form library
|
|
754
760
|
that validates asynchronously, can’t keep it open.
|
|
755
761
|
|
|
756
|
-
Enter in an input
|
|
757
|
-
not when a handler has prevented the key, as a combobox
|
|
758
|
-
option, and not when it commits an IME composition.
|
|
762
|
+
Enter in such an input, in the body or the trigger, counts the way a form
|
|
763
|
+
would count it: not when a handler has prevented the key, as a combobox
|
|
764
|
+
does to pick an option, and not when it commits an IME composition.
|
|
759
765
|
|
|
760
766
|
When a submit closes the dropdown while focus is in its body, focus returns
|
|
761
767
|
to the trigger, as it does on Escape.
|
|
@@ -1330,6 +1336,13 @@ highlight into it.
|
|
|
1330
1336
|
input, or one inside a custom trigger), where they move the caret instead
|
|
1331
1337
|
- **Type characters**: Jump to the best-matching item in the current level
|
|
1332
1338
|
|
|
1339
|
+
While text is being composed with an IME, in a searchable dropdown’s input
|
|
1340
|
+
or a text field in a custom trigger, the dropdown ignores every keydown
|
|
1341
|
+
that the browser reports as part of the composition. With a Japanese IME,
|
|
1342
|
+
the Enter that commits the text doesn’t submit (the next Enter is an
|
|
1343
|
+
ordinary one), and the arrow keys and Escape don’t move the highlight or
|
|
1344
|
+
close the dropdown. Other IMEs can report their keys differently.
|
|
1345
|
+
|
|
1333
1346
|
For accessibility, the component focuses on semantic HTML structure and
|
|
1334
1347
|
keyboard navigation. It works best when you use appropriate HTML elements
|
|
1335
1348
|
in your dropdown content (like `<ul>` and `<li>` for lists, `<button>`
|
package/dist/Dropdown.d.ts
CHANGED
|
@@ -101,7 +101,8 @@ export type Props = {
|
|
|
101
101
|
* multi-select. Defaults to !hasItems: a menu closes on submit, while a
|
|
102
102
|
* hasItems={false} dialog stays open. In a hasItems={false} dropdown, a
|
|
103
103
|
* submit is a form in the body being submitted, or Enter in a
|
|
104
|
-
* single-line input
|
|
104
|
+
* single-line input that appears in the body with no form or in the
|
|
105
|
+
* trigger.
|
|
105
106
|
*/
|
|
106
107
|
keepOpenOnSubmit?: boolean;
|
|
107
108
|
/**
|
package/dist/Dropdown.js
CHANGED
|
@@ -28,7 +28,9 @@ var isFormlessTextInput = (element) => {
|
|
|
28
28
|
const { form, type } = element;
|
|
29
29
|
return form == null && !NON_TEXT_INPUT_TYPES.includes(type);
|
|
30
30
|
};
|
|
31
|
-
var
|
|
31
|
+
var isMultilineTextField = (element) => element.tagName === "TEXTAREA" || element.isContentEditable;
|
|
32
|
+
var isIMEKeyEvent = (event) => event.isComposing || event.keyCode === 229;
|
|
33
|
+
var isSubmitKey = (event) => event.key === "Enter" && !event.defaultPrevented;
|
|
32
34
|
var getLevelRoot = (element) => element.closest(SUBMENU_SELECTOR);
|
|
33
35
|
var getSubmenuOfItem = (item) => {
|
|
34
36
|
const submenu = item.querySelector(SUBMENU_SELECTOR);
|
|
@@ -1259,6 +1261,7 @@ function RootDropdown(t0) {
|
|
|
1259
1261
|
const { altKey, ctrlKey, key: key_0, metaKey } = event_7;
|
|
1260
1262
|
const eventTarget_2 = event_7.target;
|
|
1261
1263
|
if (!dropdownElement) return;
|
|
1264
|
+
if (isIMEKeyEvent(event_7)) return;
|
|
1262
1265
|
const onEventHandled = () => {
|
|
1263
1266
|
event_7.stopPropagation();
|
|
1264
1267
|
event_7.preventDefault();
|
|
@@ -1311,7 +1314,7 @@ function RootDropdown(t0) {
|
|
|
1311
1314
|
if (!event_7.repeat) closeDropdown();
|
|
1312
1315
|
return;
|
|
1313
1316
|
}
|
|
1314
|
-
if (
|
|
1317
|
+
if (isMultilineTextField(eventTarget_2) || !isSubmitKey(event_7)) return;
|
|
1315
1318
|
} else if (isTargetUsingKeyEvents || !eventTarget_2.contains(dropdownElement)) return;
|
|
1316
1319
|
}
|
|
1317
1320
|
if (key_0 === "Enter" || key_0 === " " && !inputElementRef.current) {
|