@yuneta/gobj-ui 7.26.41 → 7.26.43
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 +510 -78
- package/dist/gobj-ui.cjs.js +1120 -326
- package/dist/gobj-ui.es.js +1120 -326
- package/package.json +1 -1
- package/scripts/validate-locales.mjs +971 -177
- package/src/c_g6_nodes_tree.js +3 -2
- package/src/c_yui_form.js +261 -154
- package/src/c_yui_fsm_graph.js +3 -2
- package/src/c_yui_gobj_tree_js.js +3 -2
- package/src/c_yui_json_graph.js +3 -2
- package/src/c_yui_nav.js +43 -28
- package/src/c_yui_node.js +51 -7
- package/src/c_yui_schema_editor.css +16 -0
- package/src/c_yui_schema_editor.js +110 -20
- package/src/c_yui_shell.css +4 -1
- package/src/c_yui_shell.js +227 -61
- package/src/c_yui_treedb_schema.js +3 -2
- package/src/c_yui_window.js +373 -62
- package/src/c_yui_window_manager.js +80 -8
- package/src/escape_taken.js +58 -0
- package/src/form_close_asks_for_edits.wiring.test.js +6 -3
- package/src/form_json_editor_names.js +3 -1
- package/src/form_json_editor_names.wiring.test.js +8 -4
- package/src/form_json_expand.wiring.test.js +6 -3
- package/src/form_json_field.wiring.test.js +8 -4
- package/src/form_label_i18n.wiring.test.js +10 -5
- package/src/form_table_edits_ask.wiring.test.js +18 -8
- package/src/form_table_rearm.wiring.test.js +13 -5
- package/src/form_table_rows.wiring.test.js +489 -0
- package/src/form_table_validator.wiring.test.js +8 -4
- package/src/form_template_field.wiring.test.js +6 -3
- package/src/g6_canvas_tab_order.css +29 -0
- package/src/g6_canvas_tab_order.js +41 -9
- package/src/g6_canvas_tab_order.wiring.test.js +107 -1
- package/src/g6_long_press_clock.test.js +8 -3
- package/src/i18n_key_functions.js +81 -27
- package/src/i18n_key_functions.test.js +402 -4
- package/src/modal_guard_back.wiring.test.js +188 -0
- package/src/named_controls.wiring.test.js +323 -19
- package/src/nav_cards_helpers.js +9 -4
- package/src/nav_item_badge.wiring.test.js +163 -15
- package/src/node_nav_events.wiring.test.js +93 -1
- package/src/route_map_model.js +59 -10
- package/src/route_map_model.test.js +90 -0
- package/src/schema_editor_diagram_click.wiring.test.js +277 -0
- package/src/schema_editor_openers.wiring.test.js +283 -0
- package/src/shell_dialog_names.wiring.test.js +149 -0
- package/src/shell_escape_taken.wiring.test.js +142 -0
- package/src/shell_focus_trap.js +30 -2
- package/src/shell_focus_trap.test.js +90 -6
- package/src/shell_modals.js +113 -22
- package/src/shell_route_map.js +15 -3
- package/src/shell_section_index.js +3 -1
- package/src/table_editor_name.wiring.test.js +10 -5
- package/src/treedb_column_title.wiring.test.js +8 -4
- package/src/treedb_graph_writes.wiring.test.js +6 -3
- package/src/treedb_json_drill.wiring.test.js +6 -3
- package/src/uplot_add_serie.test.js +6 -3
- package/src/uplot_ink.test.js +8 -4
- package/src/window_dialog.wiring.test.js +486 -0
- package/src/window_dock_band.wiring.test.js +189 -0
- package/src/window_layer.wiring.test.js +114 -0
- package/src/window_rect_rounding.wiring.test.js +121 -0
- package/src/yui_gclass_view.js +16 -1
- package/src/yui_tabulator_i18n.js +31 -1
- package/src/yui_tabulator_i18n.test.js +46 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* shell_dialog_names.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* Every dialog of the shell has a NAME for a reader: a modal is
|
|
5
|
+
* named by its title (the two halves, `title_prefix` and `title`,
|
|
6
|
+
* so the name changes language with it), or by its message when a
|
|
7
|
+
* plain one has nothing else; a question is named by its title and
|
|
8
|
+
* described by its message, or named by its message when it has
|
|
9
|
+
* no title. Up to 7.26.42 they were `role="dialog"` with no name:
|
|
10
|
+
* a reader said "dialog" and nothing else.
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2026, ArtGins.
|
|
13
|
+
* All Rights Reserved.
|
|
14
|
+
***********************************************************************/
|
|
15
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
16
|
+
import {install_dom_double} from "../test/dom_double.js";
|
|
17
|
+
|
|
18
|
+
install_dom_double();
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
SDATA_END, gclass_create,
|
|
22
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start,
|
|
23
|
+
set_log_callback,
|
|
24
|
+
} = await import("@yuneta/gobj-js");
|
|
25
|
+
const {register_c_yui_shell} = await import("./c_yui_shell.js");
|
|
26
|
+
const {
|
|
27
|
+
yui_shell_show_modal,
|
|
28
|
+
yui_shell_confirm_yesno,
|
|
29
|
+
} = await import("./shell_modals.js");
|
|
30
|
+
|
|
31
|
+
const logged = [];
|
|
32
|
+
let shell = null;
|
|
33
|
+
|
|
34
|
+
/* The nodes a reader computes the name (or the description) of
|
|
35
|
+
* `$dialog` from: those its `attr` lists, all in its own tree. */
|
|
36
|
+
function named_by($dialog, attr)
|
|
37
|
+
{
|
|
38
|
+
const ids = ($dialog.getAttribute(attr) || "").split(/\s+/).filter(Boolean);
|
|
39
|
+
return ids.map((id) => {
|
|
40
|
+
const $n = $dialog.querySelector(`#${id}`);
|
|
41
|
+
expect(!!$n, `${attr} points at '${id}', which is not in the dialog`).toBe(true);
|
|
42
|
+
return $n;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function warnings()
|
|
47
|
+
{
|
|
48
|
+
return logged.filter((l) => l.level === "warning").map((l) => l.msg);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
beforeAll(async () => {
|
|
52
|
+
const i18next = (await import("i18next")).default;
|
|
53
|
+
await i18next.init({lng: "en", resources: {}});
|
|
54
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
55
|
+
set_log_callback((level, msg) => {
|
|
56
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
57
|
+
});
|
|
58
|
+
gclass_create("C_TEST_NAMES_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
59
|
+
register_c_yui_shell();
|
|
60
|
+
const yuno = gobj_create_yuno("names_yuno", "C_TEST_NAMES_HOST", {});
|
|
61
|
+
gobj_start(yuno);
|
|
62
|
+
shell = gobj_create("nshell", "C_YUI_SHELL",
|
|
63
|
+
{config: {shell: {}}, default_route: "/home"}, yuno);
|
|
64
|
+
gobj_start(shell);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
logged.length = 0;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("a modal of the shell is named", () => {
|
|
72
|
+
test("by the two halves of its title, the kind half carrying its key", () => {
|
|
73
|
+
const $box = document.createElement("div");
|
|
74
|
+
const handle = yui_shell_show_modal(shell, $box,
|
|
75
|
+
{dialog: true, title: "keys", title_prefix: "raw_tracks", logical_class: "NAMED_SHEET"});
|
|
76
|
+
const $modal = document.querySelector(".NAMED_SHEET");
|
|
77
|
+
|
|
78
|
+
const [$prefix, $kind] = named_by($modal, "aria-labelledby");
|
|
79
|
+
expect($prefix.classList.contains("MODAL_TITLE_PREFIX")).toBe(true);
|
|
80
|
+
expect($prefix.textContent).toBe("raw_tracks");
|
|
81
|
+
expect($kind.classList.contains("MODAL_TITLE_KIND")).toBe(true);
|
|
82
|
+
expect($kind.dataset.i18n || $kind.getAttribute("i18n")).toBe("keys");
|
|
83
|
+
expect(named_by($modal, "aria-labelledby").length).toBe(2);
|
|
84
|
+
/* A form or a document is no description: read it as it is. */
|
|
85
|
+
expect($modal.getAttribute("aria-describedby")).toBe(null);
|
|
86
|
+
handle.close();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("with a title and no dialog chrome, by a title only a reader sees", () => {
|
|
90
|
+
const $box = document.createElement("div");
|
|
91
|
+
const handle = yui_shell_show_modal(shell, $box,
|
|
92
|
+
{title: "preferences", logical_class: "PLAIN_SHEET"});
|
|
93
|
+
const $modal = document.querySelector(".PLAIN_SHEET");
|
|
94
|
+
|
|
95
|
+
const [$kind] = named_by($modal, "aria-labelledby");
|
|
96
|
+
expect($kind.textContent).toBe("preferences");
|
|
97
|
+
expect($kind.closest(".MODAL_TITLE").classList.contains("is-sr-only")).toBe(true);
|
|
98
|
+
handle.close();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("with a message and no title, by its message", () => {
|
|
102
|
+
const handle = yui_shell_show_modal(shell, "nothing to show",
|
|
103
|
+
{logical_class: "MESSAGE_SHEET"});
|
|
104
|
+
const $modal = document.querySelector(".MESSAGE_SHEET");
|
|
105
|
+
|
|
106
|
+
const [$msg] = named_by($modal, "aria-labelledby");
|
|
107
|
+
expect($msg.textContent).toBe("nothing to show");
|
|
108
|
+
handle.close();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("with nothing to be named by: said", () => {
|
|
112
|
+
const handle = yui_shell_show_modal(shell, document.createElement("div"),
|
|
113
|
+
{logical_class: "NAMELESS_SHEET"});
|
|
114
|
+
const $modal = document.querySelector(".NAMELESS_SHEET");
|
|
115
|
+
expect($modal.getAttribute("aria-labelledby")).toBe(null);
|
|
116
|
+
expect(warnings().some((w) => w.includes("no name"))).toBe(true);
|
|
117
|
+
handle.close();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("a question of the shell", () => {
|
|
122
|
+
test("is named by its title and described by its message", async () => {
|
|
123
|
+
const answer = yui_shell_confirm_yesno(shell, "all changes will be lost",
|
|
124
|
+
{title: "unsaved changes", logical_class: "TITLED_QUESTION"});
|
|
125
|
+
const $q = document.querySelector(".TITLED_QUESTION");
|
|
126
|
+
|
|
127
|
+
const [$title] = named_by($q, "aria-labelledby");
|
|
128
|
+
expect($title.classList.contains("CONFIRM_TITLE")).toBe(true);
|
|
129
|
+
expect($title.dataset.i18n || $title.getAttribute("i18n")).toBe("unsaved changes");
|
|
130
|
+
const [$body] = named_by($q, "aria-describedby");
|
|
131
|
+
expect($body.textContent).toBe("all changes will be lost");
|
|
132
|
+
|
|
133
|
+
$q.querySelector(".CONFIRM_CLOSE").click();
|
|
134
|
+
expect(await answer).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("with no title, is named by its message", async () => {
|
|
138
|
+
const answer = yui_shell_confirm_yesno(shell, "delete it?",
|
|
139
|
+
{logical_class: "BARE_QUESTION"});
|
|
140
|
+
const $q = document.querySelector(".BARE_QUESTION");
|
|
141
|
+
|
|
142
|
+
const [$body] = named_by($q, "aria-labelledby");
|
|
143
|
+
expect($body.textContent).toBe("delete it?");
|
|
144
|
+
expect($q.getAttribute("aria-describedby")).toBe(null);
|
|
145
|
+
|
|
146
|
+
$q.querySelector(".CONFIRM_CLOSE").click();
|
|
147
|
+
await answer;
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* shell_escape_taken.wiring.test.js
|
|
3
|
+
*
|
|
4
|
+
* The shell's Escape closes the overlay on top of its chain (a
|
|
5
|
+
* dialog, a popup, the drawer) -- but not an Escape that what it
|
|
6
|
+
* was typed in took first. Up to 7.26.42 it closed the dialog for
|
|
7
|
+
* ANY Escape: one typed in a cell of a table being edited
|
|
8
|
+
* cancelled the edit (Tabulator removes the box) and closed the
|
|
9
|
+
* whole dialog with it.
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2026, ArtGins.
|
|
12
|
+
* All Rights Reserved.
|
|
13
|
+
***********************************************************************/
|
|
14
|
+
import {describe, test, expect, beforeAll, beforeEach} from "vitest";
|
|
15
|
+
import {install_dom_double, FakeElement} from "../test/dom_double.js";
|
|
16
|
+
|
|
17
|
+
install_dom_double();
|
|
18
|
+
|
|
19
|
+
Object.defineProperty(FakeElement.prototype, "isConnected", {
|
|
20
|
+
configurable: true,
|
|
21
|
+
get() {
|
|
22
|
+
let n = this;
|
|
23
|
+
while(n) {
|
|
24
|
+
if(n === document.documentElement) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
n = n.parentNode;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
SDATA_END, gclass_create,
|
|
35
|
+
gobj_start_up, gobj_create_yuno, gobj_create, gobj_start,
|
|
36
|
+
set_log_callback,
|
|
37
|
+
} = await import("@yuneta/gobj-js");
|
|
38
|
+
const {
|
|
39
|
+
register_c_yui_shell, yui_shell_push_escape, yui_shell_pop_escape,
|
|
40
|
+
} = await import("./c_yui_shell.js");
|
|
41
|
+
|
|
42
|
+
const logged = [];
|
|
43
|
+
let shell = null;
|
|
44
|
+
let closed = 0;
|
|
45
|
+
const close_fn = () => {
|
|
46
|
+
closed++;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/* An Escape as the window hears it, after what it was typed in had
|
|
50
|
+
* its turn (`init` says what that did). */
|
|
51
|
+
function escape_at(target, init)
|
|
52
|
+
{
|
|
53
|
+
const ev = Object.assign({
|
|
54
|
+
type: "keydown", key: "Escape", target: target,
|
|
55
|
+
defaultPrevented: false, isComposing: false,
|
|
56
|
+
preventDefault() {
|
|
57
|
+
this.defaultPrevented = true;
|
|
58
|
+
},
|
|
59
|
+
stopPropagation() {
|
|
60
|
+
}
|
|
61
|
+
}, init || {});
|
|
62
|
+
window.dispatchEvent(ev);
|
|
63
|
+
return ev;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
beforeAll(async () => {
|
|
67
|
+
const i18next = (await import("i18next")).default;
|
|
68
|
+
await i18next.init({lng: "en", resources: {}});
|
|
69
|
+
gobj_start_up(null, null, null, null, null, null, null);
|
|
70
|
+
set_log_callback((level, msg) => {
|
|
71
|
+
logged.push({level: String(level), msg: String(msg)});
|
|
72
|
+
});
|
|
73
|
+
gclass_create("C_TEST_ESC_HOST", [], [["ST_IDLE", []]], {}, 0, [SDATA_END()], {}, 0, 0, 0, 0);
|
|
74
|
+
register_c_yui_shell();
|
|
75
|
+
const yuno = gobj_create_yuno("esc_yuno", "C_TEST_ESC_HOST", {});
|
|
76
|
+
gobj_start(yuno);
|
|
77
|
+
shell = gobj_create("eshell", "C_YUI_SHELL",
|
|
78
|
+
{config: {shell: {}}, default_route: "/home"}, yuno);
|
|
79
|
+
gobj_start(shell);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
closed = 0;
|
|
84
|
+
yui_shell_push_escape(shell, "modal", close_fn);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("the shell's Escape", () => {
|
|
88
|
+
test("closes the overlay on top", () => {
|
|
89
|
+
const $button = document.createElement("button");
|
|
90
|
+
document.body.appendChild($button);
|
|
91
|
+
const ev = escape_at($button);
|
|
92
|
+
expect(closed).toBe(1);
|
|
93
|
+
expect(ev.defaultPrevented).toBe(true);
|
|
94
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
95
|
+
$button.remove();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("not one a widget used, nor one composing", () => {
|
|
99
|
+
const $input = document.createElement("input");
|
|
100
|
+
document.body.appendChild($input);
|
|
101
|
+
escape_at($input, {defaultPrevented: true});
|
|
102
|
+
escape_at($input, {isComposing: true});
|
|
103
|
+
expect(closed).toBe(0);
|
|
104
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
105
|
+
$input.remove();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("not one that went with what it was typed in (a cell editor)", () => {
|
|
109
|
+
const $editor = document.createElement("input"); /* removed: detached */
|
|
110
|
+
escape_at($editor);
|
|
111
|
+
expect(closed).toBe(0);
|
|
112
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("not one that clears a search box, but one in an empty search box", () => {
|
|
116
|
+
const $search = document.createElement("input");
|
|
117
|
+
$search.setAttribute("type", "search");
|
|
118
|
+
$search.value = "abc";
|
|
119
|
+
document.body.appendChild($search);
|
|
120
|
+
escape_at($search);
|
|
121
|
+
expect(closed).toBe(0);
|
|
122
|
+
$search.value = "";
|
|
123
|
+
escape_at($search);
|
|
124
|
+
expect(closed).toBe(1);
|
|
125
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
126
|
+
$search.remove();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("not one typed in a text editor", () => {
|
|
130
|
+
const $text = document.createElement("textarea");
|
|
131
|
+
const $editable = document.createElement("div");
|
|
132
|
+
$editable.isContentEditable = true;
|
|
133
|
+
document.body.appendChild($text);
|
|
134
|
+
document.body.appendChild($editable);
|
|
135
|
+
escape_at($text);
|
|
136
|
+
escape_at($editable);
|
|
137
|
+
expect(closed).toBe(0);
|
|
138
|
+
yui_shell_pop_escape(shell, close_fn);
|
|
139
|
+
$text.remove();
|
|
140
|
+
$editable.remove();
|
|
141
|
+
});
|
|
142
|
+
});
|
package/src/shell_focus_trap.js
CHANGED
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
* - restores focus to whatever element had it before
|
|
17
17
|
* activation when release() runs.
|
|
18
18
|
*
|
|
19
|
+
* Only a control that is DRAWN counts: focus() on one that is
|
|
20
|
+
* not (display:none) does nothing. The adaptive dialog's back
|
|
21
|
+
* arrow is the first control of every dialog and is hidden on a
|
|
22
|
+
* laptop: up to 7.26.42 the trap gave it the focus on activation
|
|
23
|
+
* (so the focus stayed outside the dialog), and every Tab after
|
|
24
|
+
* that wrapped to it, did nothing and was prevented -- the
|
|
25
|
+
* keyboard never got into the dialog.
|
|
26
|
+
*
|
|
19
27
|
* Pure module — no gobj / Yuneta dependencies. The optional
|
|
20
28
|
* second argument lets callers inject a mock document object
|
|
21
29
|
* for unit tests.
|
|
@@ -43,6 +51,26 @@ export const FOCUSABLE_SELECTOR =
|
|
|
43
51
|
const __trap_stack__ = [];
|
|
44
52
|
|
|
45
53
|
|
|
54
|
+
/* Whether `el` is drawn, so focus() on it can take. An element that
|
|
55
|
+
* cannot say (a stub with no getClientRects) is taken as drawn. */
|
|
56
|
+
function is_drawn(el)
|
|
57
|
+
{
|
|
58
|
+
if(typeof el.checkVisibility === "function") {
|
|
59
|
+
return el.checkVisibility();
|
|
60
|
+
}
|
|
61
|
+
if(typeof el.getClientRects === "function") {
|
|
62
|
+
return el.getClientRects().length > 0;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* The controls of $panel that can take the focus, in order. */
|
|
68
|
+
function focusables_of($panel)
|
|
69
|
+
{
|
|
70
|
+
return Array.from($panel.querySelectorAll(FOCUSABLE_SELECTOR)).filter(is_drawn);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
46
74
|
/***************************************************************
|
|
47
75
|
* Activate the focus-trap on $panel.
|
|
48
76
|
*
|
|
@@ -75,7 +103,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
75
103
|
if(__trap_stack__[__trap_stack__.length - 1] !== trap) {
|
|
76
104
|
return;
|
|
77
105
|
}
|
|
78
|
-
let nodes = $panel
|
|
106
|
+
let nodes = focusables_of($panel);
|
|
79
107
|
if(nodes.length === 0) {
|
|
80
108
|
return;
|
|
81
109
|
}
|
|
@@ -99,7 +127,7 @@ export function activate_focus_trap_on($panel, doc)
|
|
|
99
127
|
__trap_stack__.push(trap);
|
|
100
128
|
|
|
101
129
|
/* Move focus to the first focusable child of the panel. */
|
|
102
|
-
let firstFocusable = $panel
|
|
130
|
+
let firstFocusable = focusables_of($panel)[0];
|
|
103
131
|
if(firstFocusable && typeof firstFocusable.focus === "function") {
|
|
104
132
|
firstFocusable.focus();
|
|
105
133
|
}
|
|
@@ -46,7 +46,9 @@ function make_doc(initial_active, body_contains = true)
|
|
|
46
46
|
let listeners = [];
|
|
47
47
|
return {
|
|
48
48
|
activeElement: initial_active,
|
|
49
|
-
addEventListener(_t, fn, _opts) {
|
|
49
|
+
addEventListener(_t, fn, _opts) {
|
|
50
|
+
listeners.push(fn);
|
|
51
|
+
},
|
|
50
52
|
removeEventListener(_t, fn, _opts) {
|
|
51
53
|
let i = listeners.indexOf(fn);
|
|
52
54
|
if(i >= 0) {
|
|
@@ -105,7 +107,9 @@ test("Tab from the last focusable wraps to the first", () => {
|
|
|
105
107
|
let ev = {
|
|
106
108
|
key: "Tab",
|
|
107
109
|
shiftKey: false,
|
|
108
|
-
preventDefault() {
|
|
110
|
+
preventDefault() {
|
|
111
|
+
prevented = true;
|
|
112
|
+
}
|
|
109
113
|
};
|
|
110
114
|
doc.listeners[0](ev);
|
|
111
115
|
|
|
@@ -129,7 +133,9 @@ test("Shift+Tab from the first focusable wraps to the last", () => {
|
|
|
129
133
|
let ev = {
|
|
130
134
|
key: "Tab",
|
|
131
135
|
shiftKey: true,
|
|
132
|
-
preventDefault() {
|
|
136
|
+
preventDefault() {
|
|
137
|
+
prevented = true;
|
|
138
|
+
}
|
|
133
139
|
};
|
|
134
140
|
doc.listeners[0](ev);
|
|
135
141
|
|
|
@@ -149,7 +155,9 @@ test("non-Tab keys are ignored by the trap", () => {
|
|
|
149
155
|
let ev = {
|
|
150
156
|
key: "Escape",
|
|
151
157
|
shiftKey: false,
|
|
152
|
-
preventDefault() {
|
|
158
|
+
preventDefault() {
|
|
159
|
+
prevented = true;
|
|
160
|
+
}
|
|
153
161
|
};
|
|
154
162
|
doc.listeners[0](ev);
|
|
155
163
|
|
|
@@ -173,7 +181,9 @@ test("focus jumps into the panel when activeElement is outside", () => {
|
|
|
173
181
|
let ev = {
|
|
174
182
|
key: "Tab",
|
|
175
183
|
shiftKey: false,
|
|
176
|
-
preventDefault() {
|
|
184
|
+
preventDefault() {
|
|
185
|
+
prevented = true;
|
|
186
|
+
}
|
|
177
187
|
};
|
|
178
188
|
doc.listeners[0](ev);
|
|
179
189
|
|
|
@@ -291,9 +301,83 @@ test("an empty panel installs the listener but does nothing on Tab", () => {
|
|
|
291
301
|
let ev = {
|
|
292
302
|
key: "Tab",
|
|
293
303
|
shiftKey: false,
|
|
294
|
-
preventDefault() {
|
|
304
|
+
preventDefault() {
|
|
305
|
+
prevented = true;
|
|
306
|
+
}
|
|
295
307
|
};
|
|
296
308
|
doc.listeners[0](ev);
|
|
297
309
|
/* No focusables → trap stays out of the way. */
|
|
298
310
|
expect(prevented).toBe(false);
|
|
299
311
|
});
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
/***************************************************************
|
|
315
|
+
* A control that is not DRAWN cannot take the focus: focus() on
|
|
316
|
+
* it does nothing. The adaptive dialog's back arrow is the first
|
|
317
|
+
* control of every dialog and is display:none on a laptop (its
|
|
318
|
+
* ✕ is, on a phone): the trap gave it the focus on activation,
|
|
319
|
+
* so the focus stayed outside the dialog; and every Tab after
|
|
320
|
+
* that "wrapped" to it, did nothing and was prevented, so the
|
|
321
|
+
* keyboard never got into the dialog at all.
|
|
322
|
+
***************************************************************/
|
|
323
|
+
function drawn(name)
|
|
324
|
+
{
|
|
325
|
+
return make_focusable(name, {getClientRects: () => [{width: 10, height: 10}]});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function not_drawn(name)
|
|
329
|
+
{
|
|
330
|
+
return make_focusable(name, {getClientRects: () => []});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
test("activation gives the focus to the first DRAWN control", () => {
|
|
334
|
+
let back = not_drawn("back");
|
|
335
|
+
let close = drawn("close");
|
|
336
|
+
let panel = make_panel([back, close]);
|
|
337
|
+
let doc = make_doc(null);
|
|
338
|
+
|
|
339
|
+
let release = activate_focus_trap_on(panel, doc);
|
|
340
|
+
|
|
341
|
+
expect(back.focus_calls).toEqual([]);
|
|
342
|
+
expect(close.focus_calls).toEqual(["close.focus"]);
|
|
343
|
+
release();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("Tab and Shift+Tab wrap to the first and last DRAWN controls", () => {
|
|
347
|
+
let back = not_drawn("back");
|
|
348
|
+
let a = drawn("a");
|
|
349
|
+
let b = drawn("b");
|
|
350
|
+
let x = not_drawn("x");
|
|
351
|
+
let panel = make_panel([back, a, b, x]);
|
|
352
|
+
let doc = make_doc(null);
|
|
353
|
+
|
|
354
|
+
let release = activate_focus_trap_on(panel, doc);
|
|
355
|
+
a.focus_calls.length = 0;
|
|
356
|
+
|
|
357
|
+
doc.activeElement = b;
|
|
358
|
+
let prevented = false;
|
|
359
|
+
doc.listeners[0]({
|
|
360
|
+
key: "Tab",
|
|
361
|
+
shiftKey: false,
|
|
362
|
+
preventDefault() {
|
|
363
|
+
prevented = true;
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
expect(prevented).toBe(true);
|
|
367
|
+
expect(a.focus_calls).toEqual(["a.focus"]);
|
|
368
|
+
expect(back.focus_calls).toEqual([]);
|
|
369
|
+
|
|
370
|
+
doc.activeElement = a;
|
|
371
|
+
prevented = false;
|
|
372
|
+
doc.listeners[0]({
|
|
373
|
+
key: "Tab",
|
|
374
|
+
shiftKey: true,
|
|
375
|
+
preventDefault() {
|
|
376
|
+
prevented = true;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
expect(prevented).toBe(true);
|
|
380
|
+
expect(b.focus_calls).toEqual(["b.focus"]);
|
|
381
|
+
expect(x.focus_calls).toEqual([]);
|
|
382
|
+
release();
|
|
383
|
+
});
|