@neetechs/ui 0.0.3 → 0.0.4
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 +118 -16
- package/dist/ai/ai-action-button/ai-action-button.css +36 -35
- package/dist/ai/ai-approval-card/ai-approval-card.css +20 -17
- package/dist/ai/ai-conversation-panel/ai-conversation-panel.css +70 -26
- package/dist/ai/ai-prompt-input/ai-prompt-input.css +36 -33
- package/dist/ai/ai-proposal-card/ai-proposal-card.css +17 -17
- package/dist/ai/ai-suggestion-card/ai-suggestion-card.css +27 -25
- package/dist/ai/ai-tool-call/ai-tool-call.css +15 -14
- package/dist/appearance/cache.d.ts +6 -1
- package/dist/appearance/cache.d.ts.map +1 -1
- package/dist/appearance/cache.js +57 -1
- package/dist/appearance/cache.js.map +1 -1
- package/dist/appearance/cookie.d.ts +16 -1
- package/dist/appearance/cookie.d.ts.map +1 -1
- package/dist/appearance/cookie.js +73 -4
- package/dist/appearance/cookie.js.map +1 -1
- package/dist/appearance/index.d.ts +7 -6
- package/dist/appearance/index.d.ts.map +1 -1
- package/dist/appearance/index.js +4 -4
- package/dist/appearance/index.js.map +1 -1
- package/dist/appearance/preference.d.ts +9 -1
- package/dist/appearance/preference.d.ts.map +1 -1
- package/dist/appearance/preference.js +54 -0
- package/dist/appearance/preference.js.map +1 -1
- package/dist/appearance/theme-controller.d.ts +31 -49
- package/dist/appearance/theme-controller.d.ts.map +1 -1
- package/dist/appearance/theme-controller.js +150 -145
- package/dist/appearance/theme-controller.js.map +1 -1
- package/dist/appearance/types.d.ts +29 -2
- package/dist/appearance/types.d.ts.map +1 -1
- package/dist/behaviors/announcer.d.ts +34 -0
- package/dist/behaviors/announcer.d.ts.map +1 -0
- package/dist/behaviors/announcer.js +150 -0
- package/dist/behaviors/announcer.js.map +1 -0
- package/dist/behaviors/calendar.d.ts +15 -0
- package/dist/behaviors/calendar.d.ts.map +1 -0
- package/dist/behaviors/calendar.js +77 -0
- package/dist/behaviors/calendar.js.map +1 -0
- package/dist/behaviors/data-grid.d.ts +18 -0
- package/dist/behaviors/data-grid.d.ts.map +1 -0
- package/dist/behaviors/data-grid.js +114 -0
- package/dist/behaviors/data-grid.js.map +1 -0
- package/dist/behaviors/dialog.d.ts +14 -0
- package/dist/behaviors/dialog.d.ts.map +1 -1
- package/dist/behaviors/dialog.js +24 -6
- package/dist/behaviors/dialog.js.map +1 -1
- package/dist/behaviors/direction.d.ts +10 -0
- package/dist/behaviors/direction.d.ts.map +1 -0
- package/dist/behaviors/direction.js +24 -0
- package/dist/behaviors/direction.js.map +1 -0
- package/dist/behaviors/drawer.d.ts +15 -3
- package/dist/behaviors/drawer.d.ts.map +1 -1
- package/dist/behaviors/drawer.js +25 -10
- package/dist/behaviors/drawer.js.map +1 -1
- package/dist/behaviors/dropdown.d.ts +11 -0
- package/dist/behaviors/dropdown.d.ts.map +1 -1
- package/dist/behaviors/dropdown.js +53 -11
- package/dist/behaviors/dropdown.js.map +1 -1
- package/dist/behaviors/focus-trap.d.ts.map +1 -1
- package/dist/behaviors/focus-trap.js +45 -5
- package/dist/behaviors/focus-trap.js.map +1 -1
- package/dist/behaviors/forms.d.ts +32 -0
- package/dist/behaviors/forms.d.ts.map +1 -0
- package/dist/behaviors/forms.js +147 -0
- package/dist/behaviors/forms.js.map +1 -0
- package/dist/behaviors/index.d.ts +8 -0
- package/dist/behaviors/index.d.ts.map +1 -1
- package/dist/behaviors/index.js +8 -0
- package/dist/behaviors/index.js.map +1 -1
- package/dist/behaviors/keyboard.d.ts.map +1 -1
- package/dist/behaviors/keyboard.js +4 -2
- package/dist/behaviors/keyboard.js.map +1 -1
- package/dist/behaviors/overlay.d.ts +6 -0
- package/dist/behaviors/overlay.d.ts.map +1 -1
- package/dist/behaviors/overlay.js +93 -3
- package/dist/behaviors/overlay.js.map +1 -1
- package/dist/behaviors/state.d.ts +49 -0
- package/dist/behaviors/state.d.ts.map +1 -0
- package/dist/behaviors/state.js +220 -0
- package/dist/behaviors/state.js.map +1 -0
- package/dist/behaviors/tabs.d.ts +18 -0
- package/dist/behaviors/tabs.d.ts.map +1 -0
- package/dist/behaviors/tabs.js +103 -0
- package/dist/behaviors/tabs.js.map +1 -0
- package/dist/behaviors/viewport.d.ts +40 -0
- package/dist/behaviors/viewport.d.ts.map +1 -0
- package/dist/behaviors/viewport.js +47 -0
- package/dist/behaviors/viewport.js.map +1 -0
- package/dist/components/alert/alert.css +13 -10
- package/dist/components/avatar/avatar.css +16 -15
- package/dist/components/badge/badge.css +6 -6
- package/dist/components/breadcrumb/breadcrumb.css +12 -10
- package/dist/components/button/button.css +65 -37
- package/dist/components/card/card.css +15 -14
- package/dist/components/checkbox/checkbox.css +13 -11
- package/dist/components/chip/chip.css +22 -20
- package/dist/components/data-grid/data-grid.css +167 -16
- package/dist/components/dialog/dialog.css +127 -63
- package/dist/components/drawer/drawer.css +117 -36
- package/dist/components/dropdown/dropdown.css +32 -14
- package/dist/components/icon-button/icon-button.css +41 -37
- package/dist/components/index.css +1 -2
- package/dist/components/input/input.css +10 -10
- package/dist/components/menu/menu.css +18 -17
- package/dist/components/pagination/pagination.css +13 -12
- package/dist/components/panel/panel.css +13 -12
- package/dist/components/progress/progress.css +20 -12
- package/dist/components/radio/radio.css +11 -9
- package/dist/components/segmented-control/segmented-control.css +20 -20
- package/dist/components/select/select.css +23 -9
- package/dist/components/skeleton/skeleton.css +14 -14
- package/dist/components/split-button/split-button.css +38 -31
- package/dist/components/switch/switch.css +25 -11
- package/dist/components/table/table.css +220 -0
- package/dist/components/tabs/tabs.css +36 -32
- package/dist/components/textarea/textarea.css +13 -13
- package/dist/components/toast/toast.css +43 -21
- package/dist/components/tooltip/tooltip.css +22 -19
- package/dist/domain/billing/index.css +19 -19
- package/dist/domain/calendar/agenda-list/agenda-list.css +224 -0
- package/dist/domain/calendar/day-slice/day-slice.css +18 -17
- package/dist/domain/calendar/day-timeline/day-timeline.css +42 -34
- package/dist/domain/calendar/event-card/event-card.css +20 -18
- package/dist/domain/calendar/index.css +2 -1
- package/dist/domain/calendar/month-grid/month-grid.css +34 -28
- package/dist/domain/calendar/week-grid/week-grid.css +63 -53
- package/dist/domain/companies/index.css +30 -29
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/localization/index.d.ts +8 -0
- package/dist/localization/index.d.ts.map +1 -0
- package/dist/localization/index.js +22 -0
- package/dist/localization/index.js.map +1 -0
- package/dist/patterns/command-palette/command-palette.css +39 -31
- package/dist/patterns/company-switcher/company-switcher.css +112 -85
- package/dist/patterns/content-state/content-state.css +236 -0
- package/dist/patterns/empty-state/empty-state.css +16 -15
- package/dist/patterns/error-state/error-state.css +14 -13
- package/dist/patterns/form-layout/form-layout.css +106 -0
- package/dist/patterns/index.css +8 -3
- package/dist/patterns/loading-state/loading-state.css +9 -9
- package/dist/patterns/master-detail/master-detail.css +103 -0
- package/dist/patterns/notification-center/notification-center.css +38 -33
- package/dist/patterns/page/page.css +219 -0
- package/dist/patterns/profile-menu/profile-menu.css +15 -14
- package/dist/patterns/search-bar/search-bar.css +38 -25
- package/dist/patterns/settings-layout/settings-layout.css +150 -0
- package/dist/patterns/workflow/workflow.css +168 -0
- package/dist/shell/app-shell/app-shell.css +8 -1
- package/dist/shell/header/header.css +14 -12
- package/dist/shell/index.css +2 -2
- package/dist/shell/mobile-nav/mobile-nav.css +18 -16
- package/dist/shell/sidebar/sidebar.css +10 -10
- package/dist/styles/accessibility.css +116 -0
- package/dist/styles/animations/motion.css +2 -2
- package/dist/styles/appearance/accent.css +173 -0
- package/dist/styles/appearance/density.css +61 -0
- package/dist/styles/appearance/motion.css +40 -0
- package/dist/styles/base.css +6 -5
- package/dist/styles/index.css +8 -1
- package/dist/styles/localization.css +56 -0
- package/dist/styles/reset.css +1 -0
- package/dist/styles/responsive.css +101 -0
- package/dist/styles/themes/dark.css +95 -13
- package/dist/styles/themes/high-contrast.css +182 -11
- package/dist/styles/themes/light.css +97 -15
- package/dist/styles/tokens/breakpoints.css +29 -7
- package/dist/styles/tokens/compatibility.css +33 -0
- package/dist/styles/tokens/elevation.css +1 -7
- package/dist/styles/tokens/index.css +2 -1
- package/dist/styles/tokens/radius.css +6 -1
- package/dist/styles/tokens/spacing.css +12 -6
- package/dist/styles/tokens/typography.css +3 -2
- package/dist/styles/utilities/layout.css +20 -2
- package/dist/styles/utilities/text.css +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/docs/accessibility.md +218 -0
- package/docs/appearance-and-theming.md +118 -0
- package/docs/component-architecture.md +137 -0
- package/docs/component-guidelines.md +64 -0
- package/docs/content-and-terminology.md +207 -0
- package/docs/design-system-baseline-audit.md +226 -0
- package/docs/design-token-contract.md +279 -0
- package/docs/localization-and-rtl.md +147 -0
- package/docs/migration.md +142 -0
- package/docs/page-patterns-and-workflows.md +260 -0
- package/docs/responsive-and-adaptive-design.md +351 -0
- package/docs/semantic-role-migration-audit.md +77 -0
- package/docs/states-feedback-and-recovery.md +206 -0
- package/docs/theming.md +3 -225
- package/package.json +32 -3
- package/src/ai/ai-action-button/ai-action-button.css +36 -35
- package/src/ai/ai-approval-card/ai-approval-card.css +20 -17
- package/src/ai/ai-conversation-panel/ai-conversation-panel.css +70 -26
- package/src/ai/ai-prompt-input/ai-prompt-input.css +36 -33
- package/src/ai/ai-proposal-card/ai-proposal-card.css +17 -17
- package/src/ai/ai-suggestion-card/ai-suggestion-card.css +27 -25
- package/src/ai/ai-tool-call/ai-tool-call.css +15 -14
- package/src/appearance/cache.ts +78 -2
- package/src/appearance/cookie.ts +123 -7
- package/src/appearance/index.ts +44 -2
- package/src/appearance/preference.ts +87 -1
- package/src/appearance/theme-controller.ts +221 -233
- package/src/appearance/types.ts +40 -2
- package/src/behaviors/announcer.ts +222 -0
- package/src/behaviors/calendar.ts +92 -0
- package/src/behaviors/data-grid.ts +133 -0
- package/src/behaviors/dialog.ts +42 -7
- package/src/behaviors/direction.ts +34 -0
- package/src/behaviors/drawer.ts +48 -15
- package/src/behaviors/dropdown.ts +76 -13
- package/src/behaviors/focus-trap.ts +49 -6
- package/src/behaviors/forms.ts +205 -0
- package/src/behaviors/index.ts +9 -1
- package/src/behaviors/keyboard.ts +5 -3
- package/src/behaviors/overlay.ts +116 -3
- package/src/behaviors/state.ts +282 -0
- package/src/behaviors/tabs.ts +137 -0
- package/src/behaviors/viewport.ts +61 -0
- package/src/components/alert/alert.css +13 -10
- package/src/components/avatar/avatar.css +16 -15
- package/src/components/badge/badge.css +6 -6
- package/src/components/breadcrumb/breadcrumb.css +12 -10
- package/src/components/button/button.css +65 -37
- package/src/components/card/card.css +15 -14
- package/src/components/checkbox/checkbox.css +13 -11
- package/src/components/chip/chip.css +22 -20
- package/src/components/data-grid/data-grid.css +167 -16
- package/src/components/dialog/dialog.css +127 -63
- package/src/components/drawer/drawer.css +117 -36
- package/src/components/dropdown/dropdown.css +32 -14
- package/src/components/icon-button/icon-button.css +41 -37
- package/src/components/index.css +1 -2
- package/src/components/input/input.css +10 -10
- package/src/components/menu/menu.css +18 -17
- package/src/components/pagination/pagination.css +13 -12
- package/src/components/panel/panel.css +13 -12
- package/src/components/progress/progress.css +20 -12
- package/src/components/radio/radio.css +11 -9
- package/src/components/segmented-control/segmented-control.css +20 -20
- package/src/components/select/select.css +23 -9
- package/src/components/skeleton/skeleton.css +14 -14
- package/src/components/split-button/split-button.css +38 -31
- package/src/components/switch/switch.css +25 -11
- package/src/components/table/table.css +220 -0
- package/src/components/tabs/tabs.css +36 -32
- package/src/components/textarea/textarea.css +13 -13
- package/src/components/toast/toast.css +43 -21
- package/src/components/tooltip/tooltip.css +22 -19
- package/src/domain/billing/index.css +19 -19
- package/src/domain/calendar/agenda-list/agenda-list.css +224 -0
- package/src/domain/calendar/day-slice/day-slice.css +18 -17
- package/src/domain/calendar/day-timeline/day-timeline.css +42 -34
- package/src/domain/calendar/event-card/event-card.css +20 -18
- package/src/domain/calendar/index.css +2 -1
- package/src/domain/calendar/month-grid/month-grid.css +34 -28
- package/src/domain/calendar/week-grid/week-grid.css +63 -53
- package/src/domain/companies/index.css +30 -29
- package/src/index.ts +3 -2
- package/src/localization/index.ts +56 -0
- package/src/patterns/command-palette/command-palette.css +39 -31
- package/src/patterns/company-switcher/company-switcher.css +112 -85
- package/src/patterns/content-state/content-state.css +236 -0
- package/src/patterns/empty-state/empty-state.css +16 -15
- package/src/patterns/error-state/error-state.css +14 -13
- package/src/patterns/form-layout/form-layout.css +106 -0
- package/src/patterns/index.css +8 -3
- package/src/patterns/loading-state/loading-state.css +9 -9
- package/src/patterns/master-detail/master-detail.css +103 -0
- package/src/patterns/notification-center/notification-center.css +38 -33
- package/src/patterns/page/page.css +219 -0
- package/src/patterns/profile-menu/profile-menu.css +15 -14
- package/src/patterns/search-bar/search-bar.css +38 -25
- package/src/patterns/settings-layout/settings-layout.css +150 -0
- package/src/patterns/workflow/workflow.css +168 -0
- package/src/shell/app-shell/app-shell.css +8 -1
- package/src/shell/header/header.css +14 -12
- package/src/shell/index.css +2 -2
- package/src/shell/mobile-nav/mobile-nav.css +18 -16
- package/src/shell/sidebar/sidebar.css +10 -10
- package/src/styles/accessibility.css +116 -0
- package/src/styles/animations/motion.css +2 -2
- package/src/styles/appearance/accent.css +173 -0
- package/src/styles/appearance/density.css +61 -0
- package/src/styles/appearance/motion.css +40 -0
- package/src/styles/base.css +6 -5
- package/src/styles/index.css +8 -1
- package/src/styles/localization.css +56 -0
- package/src/styles/reset.css +1 -0
- package/src/styles/responsive.css +101 -0
- package/src/styles/themes/dark.css +95 -13
- package/src/styles/themes/high-contrast.css +182 -11
- package/src/styles/themes/light.css +97 -15
- package/src/styles/tokens/breakpoints.css +29 -7
- package/src/styles/tokens/compatibility.css +33 -0
- package/src/styles/tokens/elevation.css +1 -7
- package/src/styles/tokens/index.css +2 -1
- package/src/styles/tokens/radius.css +6 -1
- package/src/styles/tokens/spacing.css +12 -6
- package/src/styles/tokens/typography.css +3 -2
- package/src/styles/utilities/layout.css +20 -2
- package/src/styles/utilities/text.css +1 -1
- package/src/types/index.ts +2 -1
- package/dist/components/modal/modal.css +0 -318
- package/dist/patterns/workspace-switcher/workspace-switcher.css +0 -380
- package/dist/shell/right-drawer/right-drawer.css +0 -108
- package/src/components/modal/modal.css +0 -318
- package/src/patterns/workspace-switcher/workspace-switcher.css +0 -380
- package/src/shell/right-drawer/right-drawer.css +0 -108
package/src/behaviors/drawer.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { NtDisposable, NtSide } from '../types/index.js';
|
|
1
|
+
import type { NtDisposable, NtLogicalSide, NtSide } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
export type NtDrawerSide = NtSide | NtLogicalSide;
|
|
2
4
|
import {
|
|
3
5
|
ntCreateFocusTrap,
|
|
4
6
|
type NtFocusTrapController,
|
|
@@ -9,14 +11,25 @@ import {
|
|
|
9
11
|
type NtCreateOverlayOptions,
|
|
10
12
|
type NtOverlayController,
|
|
11
13
|
} from './overlay.js';
|
|
12
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
ntSetAriaControls,
|
|
16
|
+
ntSetAriaDescribedBy,
|
|
17
|
+
ntSetAriaLabelledBy,
|
|
18
|
+
} from './ids.js';
|
|
13
19
|
|
|
14
20
|
export interface NtDrawerOptions {
|
|
15
21
|
trigger?: HTMLElement | null;
|
|
16
22
|
drawer: HTMLElement;
|
|
17
23
|
backdrop?: HTMLElement | null;
|
|
18
24
|
title?: HTMLElement | null;
|
|
19
|
-
|
|
25
|
+
description?: HTMLElement | null;
|
|
26
|
+
/** Modal drawers trap focus; nonmodal drawers behave as a region/navigation landmark. */
|
|
27
|
+
modal?: boolean;
|
|
28
|
+
role?: 'dialog' | 'region' | 'navigation';
|
|
29
|
+
/** Canonical logical/physical placement. Prefer inline-start or inline-end. */
|
|
30
|
+
placement?: NtDrawerSide;
|
|
31
|
+
/** @deprecated Use `placement`. Retained for existing consumers. */
|
|
32
|
+
side?: NtDrawerSide;
|
|
20
33
|
initialOpen?: boolean;
|
|
21
34
|
closeOnEscape?: boolean;
|
|
22
35
|
closeOnOutsideClick?: boolean;
|
|
@@ -31,7 +44,9 @@ export interface NtDrawerController extends NtDisposable {
|
|
|
31
44
|
readonly drawer: HTMLElement;
|
|
32
45
|
readonly trigger: HTMLElement | null;
|
|
33
46
|
readonly backdrop: HTMLElement | null;
|
|
34
|
-
readonly
|
|
47
|
+
readonly placement: NtDrawerSide;
|
|
48
|
+
/** @deprecated Use `placement`. */
|
|
49
|
+
readonly side: NtDrawerSide;
|
|
35
50
|
readonly isOpen: boolean;
|
|
36
51
|
open(): void;
|
|
37
52
|
close(): void;
|
|
@@ -44,17 +59,23 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
44
59
|
drawer,
|
|
45
60
|
backdrop = null,
|
|
46
61
|
title = null,
|
|
47
|
-
|
|
62
|
+
description = null,
|
|
63
|
+
modal = true,
|
|
64
|
+
role = modal ? 'dialog' : 'region',
|
|
65
|
+
placement,
|
|
66
|
+
side,
|
|
48
67
|
initialOpen = false,
|
|
49
68
|
closeOnEscape = true,
|
|
50
69
|
closeOnOutsideClick = true,
|
|
51
|
-
lockScroll =
|
|
70
|
+
lockScroll = modal,
|
|
52
71
|
restoreFocus = true,
|
|
53
72
|
initialFocus = null,
|
|
54
73
|
onOpen,
|
|
55
74
|
onClose,
|
|
56
75
|
} = options;
|
|
57
76
|
|
|
77
|
+
const resolvedPlacement = placement ?? side ?? 'inline-end';
|
|
78
|
+
|
|
58
79
|
let isOpen = false;
|
|
59
80
|
|
|
60
81
|
const overlayOptions: NtCreateOverlayOptions = {
|
|
@@ -62,6 +83,8 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
62
83
|
closeOnOutsideClick,
|
|
63
84
|
lockScroll,
|
|
64
85
|
outsideElements: trigger ? [trigger] : [],
|
|
86
|
+
inertBackground: modal,
|
|
87
|
+
inertExcludeElements: [backdrop],
|
|
65
88
|
onClose: () => {
|
|
66
89
|
close();
|
|
67
90
|
},
|
|
@@ -77,13 +100,15 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
77
100
|
});
|
|
78
101
|
|
|
79
102
|
function syncAttributes(): void {
|
|
80
|
-
drawer.setAttribute('role',
|
|
81
|
-
drawer.setAttribute('aria-modal', 'true');
|
|
103
|
+
drawer.setAttribute('role', role);
|
|
104
|
+
if (modal) drawer.setAttribute('aria-modal', 'true');
|
|
105
|
+
else drawer.removeAttribute('aria-modal');
|
|
82
106
|
drawer.dataset.state = isOpen ? 'open' : 'closed';
|
|
83
|
-
drawer.dataset.side =
|
|
107
|
+
drawer.dataset.side = resolvedPlacement;
|
|
108
|
+
drawer.dataset.placement = resolvedPlacement;
|
|
84
109
|
|
|
85
|
-
if (!drawer.classList.contains(`nt-drawer--${
|
|
86
|
-
drawer.classList.add(`nt-drawer--${
|
|
110
|
+
if (!drawer.classList.contains(`nt-drawer--${resolvedPlacement}`)) {
|
|
111
|
+
drawer.classList.add(`nt-drawer--${resolvedPlacement}`);
|
|
87
112
|
}
|
|
88
113
|
|
|
89
114
|
if (backdrop) {
|
|
@@ -99,6 +124,10 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
99
124
|
ntSetAriaLabelledBy(drawer, title, 'nt-drawer-title');
|
|
100
125
|
}
|
|
101
126
|
|
|
127
|
+
if (description) {
|
|
128
|
+
ntSetAriaDescribedBy(drawer, description, 'nt-drawer-description');
|
|
129
|
+
}
|
|
130
|
+
|
|
102
131
|
if (isOpen) {
|
|
103
132
|
drawer.removeAttribute('hidden');
|
|
104
133
|
backdrop?.removeAttribute('hidden');
|
|
@@ -117,7 +146,7 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
117
146
|
isOpen = true;
|
|
118
147
|
syncAttributes();
|
|
119
148
|
overlay.activate();
|
|
120
|
-
focusTrap.activate();
|
|
149
|
+
if (modal) focusTrap.activate();
|
|
121
150
|
onOpen?.();
|
|
122
151
|
}
|
|
123
152
|
|
|
@@ -127,8 +156,8 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
127
156
|
}
|
|
128
157
|
|
|
129
158
|
isOpen = false;
|
|
130
|
-
focusTrap.deactivate();
|
|
131
159
|
overlay.deactivate();
|
|
160
|
+
if (modal) focusTrap.deactivate();
|
|
132
161
|
syncAttributes();
|
|
133
162
|
onClose?.();
|
|
134
163
|
}
|
|
@@ -158,7 +187,8 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
158
187
|
drawer,
|
|
159
188
|
trigger,
|
|
160
189
|
backdrop,
|
|
161
|
-
|
|
190
|
+
placement: resolvedPlacement,
|
|
191
|
+
side: resolvedPlacement,
|
|
162
192
|
|
|
163
193
|
get isOpen() {
|
|
164
194
|
return isOpen;
|
|
@@ -174,4 +204,7 @@ export function ntCreateDrawer(options: NtDrawerOptions): NtDrawerController {
|
|
|
174
204
|
overlay.destroy();
|
|
175
205
|
},
|
|
176
206
|
};
|
|
177
|
-
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Unprefixed compatibility export; canonical Neetechs code uses `ntCreateDrawer`. */
|
|
210
|
+
export const createDrawer = ntCreateDrawer;
|
|
@@ -27,6 +27,8 @@ export interface NtDropdownOptions {
|
|
|
27
27
|
closeOnOutsideClick?: boolean;
|
|
28
28
|
closeOnSelect?: boolean;
|
|
29
29
|
loopFocus?: boolean;
|
|
30
|
+
pattern?: 'menu' | 'listbox';
|
|
31
|
+
typeahead?: boolean;
|
|
30
32
|
onOpen?: () => void;
|
|
31
33
|
onClose?: () => void;
|
|
32
34
|
onSelect?: (item: HTMLElement, event: Event) => void;
|
|
@@ -48,7 +50,7 @@ const DEFAULT_ITEM_SELECTOR = [
|
|
|
48
50
|
'.nt-menu__item',
|
|
49
51
|
].join(',');
|
|
50
52
|
|
|
51
|
-
export function
|
|
53
|
+
export function ntCreateMenuPopover(
|
|
52
54
|
options: NtDropdownOptions,
|
|
53
55
|
): NtDropdownController {
|
|
54
56
|
const {
|
|
@@ -62,6 +64,8 @@ export function ntCreateDropdown(
|
|
|
62
64
|
closeOnOutsideClick = true,
|
|
63
65
|
closeOnSelect = true,
|
|
64
66
|
loopFocus = true,
|
|
67
|
+
pattern = 'menu',
|
|
68
|
+
typeahead = true,
|
|
65
69
|
onOpen,
|
|
66
70
|
onClose,
|
|
67
71
|
onSelect,
|
|
@@ -69,6 +73,8 @@ export function ntCreateDropdown(
|
|
|
69
73
|
|
|
70
74
|
let isOpen = false;
|
|
71
75
|
let rovingFocus: NtRovingFocusController | null = null;
|
|
76
|
+
let typeaheadBuffer = '';
|
|
77
|
+
let typeaheadTimer = 0;
|
|
72
78
|
|
|
73
79
|
const overlayOptions: NtCreateOverlayOptions = {
|
|
74
80
|
closeOnEscape,
|
|
@@ -83,13 +89,14 @@ export function ntCreateDropdown(
|
|
|
83
89
|
const overlay: NtOverlayController = ntCreateOverlay(content, overlayOptions);
|
|
84
90
|
|
|
85
91
|
function syncAttributes(): void {
|
|
86
|
-
trigger.setAttribute('aria-haspopup',
|
|
92
|
+
trigger.setAttribute('aria-haspopup', pattern);
|
|
87
93
|
trigger.setAttribute('aria-expanded', String(isOpen));
|
|
88
94
|
ntSetAriaControls(trigger, content, 'nt-dropdown');
|
|
89
95
|
|
|
90
96
|
content.dataset.state = isOpen ? 'open' : 'closed';
|
|
91
97
|
content.dataset.side = side;
|
|
92
98
|
content.dataset.align = align;
|
|
99
|
+
content.setAttribute('role', pattern);
|
|
93
100
|
|
|
94
101
|
if (isOpen) {
|
|
95
102
|
content.removeAttribute('hidden');
|
|
@@ -104,6 +111,12 @@ export function ntCreateDropdown(
|
|
|
104
111
|
return;
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
for (const item of content.querySelectorAll<HTMLElement>(itemSelector)) {
|
|
115
|
+
if (!item.hasAttribute('role')) {
|
|
116
|
+
item.setAttribute('role', pattern === 'menu' ? 'menuitem' : 'option');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
107
120
|
rovingFocus = ntCreateRovingFocus({
|
|
108
121
|
root: content,
|
|
109
122
|
itemSelector,
|
|
@@ -174,16 +187,7 @@ export function ntCreateDropdown(
|
|
|
174
187
|
return;
|
|
175
188
|
}
|
|
176
189
|
|
|
177
|
-
|
|
178
|
-
event.preventDefault();
|
|
179
|
-
toggle();
|
|
180
|
-
|
|
181
|
-
if (!isOpen) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
queueMicrotask(focusFirstItem);
|
|
186
|
-
}
|
|
190
|
+
// Enter/Space remain native button behavior and are handled by click.
|
|
187
191
|
};
|
|
188
192
|
|
|
189
193
|
const handleContentClick = (event: MouseEvent) => {
|
|
@@ -222,6 +226,37 @@ export function ntCreateDropdown(
|
|
|
222
226
|
return;
|
|
223
227
|
}
|
|
224
228
|
|
|
229
|
+
if (
|
|
230
|
+
typeahead &&
|
|
231
|
+
event.key.length === 1 &&
|
|
232
|
+
!event.altKey &&
|
|
233
|
+
!event.ctrlKey &&
|
|
234
|
+
!event.metaKey
|
|
235
|
+
) {
|
|
236
|
+
typeaheadBuffer += event.key.toLocaleLowerCase();
|
|
237
|
+
const ownerWindow = content.ownerDocument.defaultView;
|
|
238
|
+
if (ownerWindow) {
|
|
239
|
+
ownerWindow.clearTimeout(typeaheadTimer);
|
|
240
|
+
typeaheadTimer = ownerWindow.setTimeout(() => {
|
|
241
|
+
typeaheadBuffer = '';
|
|
242
|
+
}, 500);
|
|
243
|
+
}
|
|
244
|
+
const items = Array.from(content.querySelectorAll<HTMLElement>(itemSelector)).filter(
|
|
245
|
+
(item) =>
|
|
246
|
+
!item.hasAttribute('disabled') &&
|
|
247
|
+
item.getAttribute('aria-disabled') !== 'true' &&
|
|
248
|
+
item.dataset.disabled !== 'true',
|
|
249
|
+
);
|
|
250
|
+
const match = items.find((item) =>
|
|
251
|
+
(item.textContent ?? '').trim().toLocaleLowerCase().startsWith(typeaheadBuffer),
|
|
252
|
+
);
|
|
253
|
+
if (match) {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
match.focus({ preventScroll: true });
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
225
260
|
if (!ntIsActivationKey(event)) {
|
|
226
261
|
return;
|
|
227
262
|
}
|
|
@@ -238,6 +273,15 @@ export function ntCreateDropdown(
|
|
|
238
273
|
return;
|
|
239
274
|
}
|
|
240
275
|
|
|
276
|
+
if (
|
|
277
|
+
item.hasAttribute('disabled') ||
|
|
278
|
+
item.getAttribute('aria-disabled') === 'true' ||
|
|
279
|
+
item.dataset.disabled === 'true'
|
|
280
|
+
) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
241
285
|
event.preventDefault();
|
|
242
286
|
onSelect?.(item, event);
|
|
243
287
|
|
|
@@ -275,7 +319,26 @@ export function ntCreateDropdown(
|
|
|
275
319
|
content.removeEventListener('click', handleContentClick);
|
|
276
320
|
content.removeEventListener('keydown', handleContentKeyDown);
|
|
277
321
|
rovingFocus?.destroy();
|
|
322
|
+
content.ownerDocument.defaultView?.clearTimeout(typeaheadTimer);
|
|
278
323
|
overlay.destroy();
|
|
279
324
|
},
|
|
280
325
|
};
|
|
281
|
-
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Compatibility name for the canonical menu/popover controller.
|
|
330
|
+
* The public dropdown pattern remains supported.
|
|
331
|
+
*/
|
|
332
|
+
export function ntCreateDropdown(
|
|
333
|
+
options: NtDropdownOptions,
|
|
334
|
+
): NtDropdownController {
|
|
335
|
+
return ntCreateMenuPopover(options);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export type NtMenuOptions = Omit<NtDropdownOptions, 'pattern'>;
|
|
339
|
+
export type NtMenuController = NtDropdownController;
|
|
340
|
+
|
|
341
|
+
/** Creates the canonical application-menu behavior over the shared popover foundation. */
|
|
342
|
+
export function ntCreateMenu(options: NtMenuOptions): NtMenuController {
|
|
343
|
+
return ntCreateMenuPopover({ ...options, pattern: 'menu' });
|
|
344
|
+
}
|
|
@@ -33,6 +33,26 @@ export interface NtFocusTrapController extends NtDisposable {
|
|
|
33
33
|
focusLast(): void;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const focusTrapStacks = new WeakMap<Document, symbol[]>();
|
|
37
|
+
|
|
38
|
+
function pushFocusTrap(doc: Document, token: symbol): void {
|
|
39
|
+
const stack = focusTrapStacks.get(doc) ?? [];
|
|
40
|
+
stack.push(token);
|
|
41
|
+
focusTrapStacks.set(doc, stack);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function removeFocusTrap(doc: Document, token: symbol): void {
|
|
45
|
+
const stack = focusTrapStacks.get(doc);
|
|
46
|
+
if (!stack) return;
|
|
47
|
+
const index = stack.lastIndexOf(token);
|
|
48
|
+
if (index >= 0) stack.splice(index, 1);
|
|
49
|
+
if (stack.length === 0) focusTrapStacks.delete(doc);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isTopFocusTrap(doc: Document, token: symbol): boolean {
|
|
53
|
+
return focusTrapStacks.get(doc)?.at(-1) === token;
|
|
54
|
+
}
|
|
55
|
+
|
|
36
56
|
export function ntIsFocusable(element: HTMLElement): boolean {
|
|
37
57
|
if (element.hasAttribute('disabled')) {
|
|
38
58
|
return false;
|
|
@@ -46,7 +66,11 @@ export function ntIsFocusable(element: HTMLElement): boolean {
|
|
|
46
66
|
return false;
|
|
47
67
|
}
|
|
48
68
|
|
|
49
|
-
|
|
69
|
+
if (element.closest('[inert], [aria-hidden="true"]')) return false;
|
|
70
|
+
|
|
71
|
+
const ownerWindow = element.ownerDocument.defaultView;
|
|
72
|
+
if (!ownerWindow) return false;
|
|
73
|
+
const style = ownerWindow.getComputedStyle(element);
|
|
50
74
|
|
|
51
75
|
if (style.display === 'none' || style.visibility === 'hidden') {
|
|
52
76
|
return false;
|
|
@@ -116,8 +140,14 @@ export function ntCreateFocusTrap(
|
|
|
116
140
|
} = options;
|
|
117
141
|
|
|
118
142
|
const ownerDocument = root.ownerDocument;
|
|
143
|
+
const stackToken = Symbol('nt-focus-trap');
|
|
119
144
|
let active = false;
|
|
120
145
|
let previousActiveElement: HTMLElement | null = null;
|
|
146
|
+
let activationGeneration = 0;
|
|
147
|
+
|
|
148
|
+
if (!root.hasAttribute('tabindex')) {
|
|
149
|
+
root.tabIndex = -1;
|
|
150
|
+
}
|
|
121
151
|
|
|
122
152
|
function getFallbackFocus(): HTMLElement {
|
|
123
153
|
return ntResolveFocusTarget(fallbackFocus) ?? root;
|
|
@@ -150,7 +180,7 @@ export function ntCreateFocusTrap(
|
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
function handleKeyDown(event: KeyboardEvent): void {
|
|
153
|
-
if (!active) {
|
|
183
|
+
if (!active || !isTopFocusTrap(ownerDocument, stackToken)) {
|
|
154
184
|
return;
|
|
155
185
|
}
|
|
156
186
|
|
|
@@ -194,7 +224,7 @@ export function ntCreateFocusTrap(
|
|
|
194
224
|
}
|
|
195
225
|
|
|
196
226
|
function handleFocusIn(event: FocusEvent): void {
|
|
197
|
-
if (!active) {
|
|
227
|
+
if (!active || !isTopFocusTrap(ownerDocument, stackToken)) {
|
|
198
228
|
return;
|
|
199
229
|
}
|
|
200
230
|
|
|
@@ -213,6 +243,9 @@ export function ntCreateFocusTrap(
|
|
|
213
243
|
}
|
|
214
244
|
|
|
215
245
|
active = true;
|
|
246
|
+
activationGeneration += 1;
|
|
247
|
+
const generation = activationGeneration;
|
|
248
|
+
pushFocusTrap(ownerDocument, stackToken);
|
|
216
249
|
|
|
217
250
|
const activeElement = ownerDocument.activeElement;
|
|
218
251
|
|
|
@@ -222,7 +255,15 @@ export function ntCreateFocusTrap(
|
|
|
222
255
|
ownerDocument.addEventListener('keydown', handleKeyDown);
|
|
223
256
|
ownerDocument.addEventListener('focusin', handleFocusIn);
|
|
224
257
|
|
|
225
|
-
queueMicrotask(
|
|
258
|
+
queueMicrotask(() => {
|
|
259
|
+
if (
|
|
260
|
+
active &&
|
|
261
|
+
generation === activationGeneration &&
|
|
262
|
+
isTopFocusTrap(ownerDocument, stackToken)
|
|
263
|
+
) {
|
|
264
|
+
focusInitial();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
226
267
|
}
|
|
227
268
|
|
|
228
269
|
function deactivate(): void {
|
|
@@ -231,11 +272,13 @@ export function ntCreateFocusTrap(
|
|
|
231
272
|
}
|
|
232
273
|
|
|
233
274
|
active = false;
|
|
275
|
+
activationGeneration += 1;
|
|
276
|
+
removeFocusTrap(ownerDocument, stackToken);
|
|
234
277
|
|
|
235
278
|
ownerDocument.removeEventListener('keydown', handleKeyDown);
|
|
236
279
|
ownerDocument.removeEventListener('focusin', handleFocusIn);
|
|
237
280
|
|
|
238
|
-
if (restoreFocus) {
|
|
281
|
+
if (restoreFocus && previousActiveElement?.isConnected) {
|
|
239
282
|
ntFocusElement(previousActiveElement, { preventScroll });
|
|
240
283
|
}
|
|
241
284
|
|
|
@@ -258,4 +301,4 @@ export function ntCreateFocusTrap(
|
|
|
258
301
|
deactivate();
|
|
259
302
|
},
|
|
260
303
|
};
|
|
261
|
-
}
|
|
304
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { ntEnsureId } from './ids.js';
|
|
2
|
+
import type { NtDisposable } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
export interface NtConnectFieldOptions {
|
|
5
|
+
control: HTMLElement;
|
|
6
|
+
label?: HTMLElement | null;
|
|
7
|
+
description?: HTMLElement | null;
|
|
8
|
+
error?: HTMLElement | null;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function appendIdReference(element: HTMLElement, attribute: string, id: string): void {
|
|
14
|
+
const ids = new Set((element.getAttribute(attribute) ?? '').split(/\s+/).filter(Boolean));
|
|
15
|
+
ids.add(id);
|
|
16
|
+
element.setAttribute(attribute, [...ids].join(' '));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Connects stable field naming/description/error references without inventing copy. */
|
|
20
|
+
export function ntConnectField(options: NtConnectFieldOptions): void {
|
|
21
|
+
const { control, label = null, description = null, error = null } = options;
|
|
22
|
+
const controlId = ntEnsureId(control, 'nt-field');
|
|
23
|
+
|
|
24
|
+
if (label) {
|
|
25
|
+
const labelId = ntEnsureId(label, 'nt-field-label');
|
|
26
|
+
const isLabel = label.tagName.toLowerCase() === 'label';
|
|
27
|
+
if (isLabel) label.setAttribute('for', controlId);
|
|
28
|
+
else control.setAttribute('aria-labelledby', labelId);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (description) {
|
|
32
|
+
appendIdReference(control, 'aria-describedby', ntEnsureId(description, 'nt-field-help'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (error) {
|
|
36
|
+
appendIdReference(control, 'aria-describedby', ntEnsureId(error, 'nt-field-error'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (options.required !== undefined) {
|
|
40
|
+
control.setAttribute('aria-required', String(options.required));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (options.invalid !== undefined) {
|
|
44
|
+
control.setAttribute('aria-invalid', String(options.invalid));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function ntFocusErrorSummary(summary: HTMLElement): void {
|
|
49
|
+
if (!summary.hasAttribute('tabindex')) summary.tabIndex = -1;
|
|
50
|
+
summary.focus({ preventScroll: false });
|
|
51
|
+
summary.scrollIntoView({ block: 'nearest' });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type NtFormSubmissionState = 'editing' | 'submitting' | 'success' | 'failure';
|
|
55
|
+
|
|
56
|
+
export interface NtCreateFormControllerOptions {
|
|
57
|
+
form: HTMLFormElement;
|
|
58
|
+
errorSummary?: HTMLElement | null;
|
|
59
|
+
validate?: (form: HTMLFormElement) => boolean | Promise<boolean>;
|
|
60
|
+
submit: (form: HTMLFormElement, signal: AbortSignal | null) => Promise<unknown> | unknown;
|
|
61
|
+
submitControls?: HTMLElement[];
|
|
62
|
+
successResetDelay?: number | null;
|
|
63
|
+
failureResetDelay?: number | null;
|
|
64
|
+
onStateChange?: (state: NtFormSubmissionState) => void;
|
|
65
|
+
onSuccess?: (value: unknown) => void;
|
|
66
|
+
onFailure?: (error: unknown) => void;
|
|
67
|
+
onValidationFailure?: () => void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface NtFormController extends NtDisposable {
|
|
71
|
+
readonly state: NtFormSubmissionState;
|
|
72
|
+
reset(): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function ntCreateFormController(options: NtCreateFormControllerOptions): NtFormController {
|
|
76
|
+
const {
|
|
77
|
+
form,
|
|
78
|
+
errorSummary = null,
|
|
79
|
+
validate,
|
|
80
|
+
submit,
|
|
81
|
+
submitControls = Array.from(form.querySelectorAll<HTMLElement>('[type="submit"], button:not([type])')),
|
|
82
|
+
successResetDelay = 1200,
|
|
83
|
+
failureResetDelay = null,
|
|
84
|
+
onStateChange,
|
|
85
|
+
onSuccess,
|
|
86
|
+
onFailure,
|
|
87
|
+
onValidationFailure,
|
|
88
|
+
} = options;
|
|
89
|
+
|
|
90
|
+
const ownerWindow = form.ownerDocument.defaultView;
|
|
91
|
+
let state: NtFormSubmissionState = 'editing';
|
|
92
|
+
let resetTimer = 0;
|
|
93
|
+
let abortController: AbortController | null = null;
|
|
94
|
+
|
|
95
|
+
function clearResetTimer(): void {
|
|
96
|
+
if (resetTimer && ownerWindow) ownerWindow.clearTimeout(resetTimer);
|
|
97
|
+
resetTimer = 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function setState(next: NtFormSubmissionState): void {
|
|
101
|
+
clearResetTimer();
|
|
102
|
+
state = next;
|
|
103
|
+
form.dataset.ntState = next === 'failure' ? 'error' : next === 'submitting' ? 'pending' : next;
|
|
104
|
+
form.dataset.ntSubmissionState = next;
|
|
105
|
+
|
|
106
|
+
const pending = next === 'submitting';
|
|
107
|
+
form.setAttribute('aria-busy', String(pending));
|
|
108
|
+
for (const control of submitControls) {
|
|
109
|
+
control.dataset.ntState = pending ? 'pending' : next === 'success' ? 'success' : next === 'failure' ? 'error' : 'idle';
|
|
110
|
+
control.setAttribute('aria-busy', String(pending));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
onStateChange?.(next);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function scheduleReset(delay: number | null): void {
|
|
117
|
+
if (delay === null) return;
|
|
118
|
+
if (delay <= 0) {
|
|
119
|
+
reset();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (ownerWindow) resetTimer = ownerWindow.setTimeout(reset, delay);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function reset(): void {
|
|
126
|
+
clearResetTimer();
|
|
127
|
+
state = 'editing';
|
|
128
|
+
form.dataset.ntState = 'idle';
|
|
129
|
+
form.dataset.ntSubmissionState = 'editing';
|
|
130
|
+
form.removeAttribute('aria-busy');
|
|
131
|
+
for (const control of submitControls) {
|
|
132
|
+
control.dataset.ntState = 'idle';
|
|
133
|
+
control.removeAttribute('aria-busy');
|
|
134
|
+
}
|
|
135
|
+
onStateChange?.('editing');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function handleSubmit(event: SubmitEvent): Promise<void> {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
|
|
141
|
+
if (state === 'submitting') {
|
|
142
|
+
event.stopImmediatePropagation();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const nativeValid = typeof form.checkValidity === 'function' ? form.checkValidity() : true;
|
|
147
|
+
const customValid = validate ? await validate(form) : true;
|
|
148
|
+
if (!nativeValid || !customValid) {
|
|
149
|
+
setState('failure');
|
|
150
|
+
errorSummary?.removeAttribute('hidden');
|
|
151
|
+
if (errorSummary) ntFocusErrorSummary(errorSummary);
|
|
152
|
+
onValidationFailure?.();
|
|
153
|
+
scheduleReset(failureResetDelay);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setState('submitting');
|
|
158
|
+
abortController = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const value = await submit(form, abortController?.signal ?? null);
|
|
162
|
+
setState('success');
|
|
163
|
+
onSuccess?.(value);
|
|
164
|
+
scheduleReset(successResetDelay);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
setState('failure');
|
|
167
|
+
errorSummary?.removeAttribute('hidden');
|
|
168
|
+
onFailure?.(error);
|
|
169
|
+
scheduleReset(failureResetDelay);
|
|
170
|
+
} finally {
|
|
171
|
+
abortController = null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const submitListener = (event: SubmitEvent) => {
|
|
176
|
+
void handleSubmit(event);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const inputListener = (event: Event) => {
|
|
180
|
+
const target = event.target;
|
|
181
|
+
if (target instanceof HTMLElement) target.dataset.ntDirty = 'true';
|
|
182
|
+
if (state === 'failure') {
|
|
183
|
+
form.dataset.ntSubmissionState = 'editing';
|
|
184
|
+
form.dataset.ntState = 'idle';
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
form.addEventListener('submit', submitListener);
|
|
189
|
+
form.addEventListener('input', inputListener);
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
get state() {
|
|
193
|
+
return state;
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
reset,
|
|
197
|
+
|
|
198
|
+
destroy() {
|
|
199
|
+
form.removeEventListener('submit', submitListener);
|
|
200
|
+
form.removeEventListener('input', inputListener);
|
|
201
|
+
if (abortController) abortController.abort();
|
|
202
|
+
reset();
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
package/src/behaviors/index.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export * from './ids.js';
|
|
2
|
+
export * from './direction.js';
|
|
2
3
|
export * from './keyboard.js';
|
|
3
4
|
export * from './focus-trap.js';
|
|
4
5
|
export * from './overlay.js';
|
|
5
6
|
export * from './dialog.js';
|
|
6
7
|
export * from './drawer.js';
|
|
7
|
-
export * from './dropdown.js';
|
|
8
|
+
export * from './dropdown.js';
|
|
9
|
+
export * from './tabs.js';
|
|
10
|
+
export * from './announcer.js';
|
|
11
|
+
export * from './forms.js';
|
|
12
|
+
export * from './data-grid.js';
|
|
13
|
+
export * from './calendar.js';
|
|
14
|
+
export * from './state.js';
|
|
15
|
+
export * from './viewport.js';
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
NtRovingFocusController,
|
|
4
4
|
NtRovingFocusOptions,
|
|
5
5
|
} from '../types/index.js';
|
|
6
|
+
import { ntGetInlineArrowKeys } from './direction.js';
|
|
6
7
|
|
|
7
8
|
export const NT_KEYS = {
|
|
8
9
|
arrowDown: 'ArrowDown',
|
|
@@ -229,6 +230,7 @@ export function ntCreateRovingFocus(
|
|
|
229
230
|
const isHorizontal =
|
|
230
231
|
orientation === 'horizontal' || orientation === 'both';
|
|
231
232
|
const isVertical = orientation === 'vertical' || orientation === 'both';
|
|
233
|
+
const inlineKeys = ntGetInlineArrowKeys(root);
|
|
232
234
|
|
|
233
235
|
if (event.key === NT_KEYS.home) {
|
|
234
236
|
event.preventDefault();
|
|
@@ -244,7 +246,7 @@ export function ntCreateRovingFocus(
|
|
|
244
246
|
|
|
245
247
|
if (
|
|
246
248
|
(isVertical && event.key === NT_KEYS.arrowDown) ||
|
|
247
|
-
(isHorizontal && event.key ===
|
|
249
|
+
(isHorizontal && event.key === inlineKeys.next)
|
|
248
250
|
) {
|
|
249
251
|
event.preventDefault();
|
|
250
252
|
focusNext();
|
|
@@ -253,7 +255,7 @@ export function ntCreateRovingFocus(
|
|
|
253
255
|
|
|
254
256
|
if (
|
|
255
257
|
(isVertical && event.key === NT_KEYS.arrowUp) ||
|
|
256
|
-
(isHorizontal && event.key ===
|
|
258
|
+
(isHorizontal && event.key === inlineKeys.previous)
|
|
257
259
|
) {
|
|
258
260
|
event.preventDefault();
|
|
259
261
|
focusPrevious();
|
|
@@ -300,4 +302,4 @@ export function ntCreateRovingFocus(
|
|
|
300
302
|
root.removeEventListener('focusin', onFocusIn);
|
|
301
303
|
},
|
|
302
304
|
};
|
|
303
|
-
}
|
|
305
|
+
}
|