@wordpress/dom 3.2.2-next.5df0cd52b7.0 → 3.2.5
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 +0 -1
- package/build/dom/caret-range-from-point.js +7 -3
- package/build/dom/caret-range-from-point.js.map +1 -1
- package/build/dom/is-edge.js +1 -1
- package/build/dom/is-edge.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +108 -0
- package/build/dom/place-caret-at-edge.js.map +1 -0
- package/build/dom/place-caret-at-horizontal-edge.js +2 -84
- package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build/dom/place-caret-at-vertical-edge.js +6 -56
- package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build/focusable.js +29 -18
- package/build/focusable.js.map +1 -1
- package/build/phrasing-content.js +1 -1
- package/build/phrasing-content.js.map +1 -1
- package/build/tabbable.js +2 -2
- package/build/tabbable.js.map +1 -1
- package/build-module/dom/caret-range-from-point.js +7 -3
- package/build-module/dom/caret-range-from-point.js.map +1 -1
- package/build-module/dom/is-edge.js +1 -1
- package/build-module/dom/is-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +95 -0
- package/build-module/dom/place-caret-at-edge.js.map +1 -0
- package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
- package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build-module/focusable.js +29 -18
- package/build-module/focusable.js.map +1 -1
- package/build-module/phrasing-content.js +1 -1
- package/build-module/phrasing-content.js.map +1 -1
- package/build-module/tabbable.js +2 -2
- package/build-module/tabbable.js.map +1 -1
- package/build-types/dom/caret-range-from-point.d.ts +12 -4
- package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts +9 -0
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
- package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
- package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
- package/build-types/focusable.d.ts +11 -2
- package/build-types/focusable.d.ts.map +1 -1
- package/build-types/phrasing-content.d.ts +2 -4
- package/build-types/phrasing-content.d.ts.map +1 -1
- package/build-types/tabbable.d.ts +3 -3
- package/build-types/tabbable.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/dom/caret-range-from-point.js +8 -3
- package/src/dom/is-edge.js +4 -1
- package/src/dom/place-caret-at-edge.js +95 -0
- package/src/dom/place-caret-at-horizontal-edge.js +2 -83
- package/src/dom/place-caret-at-vertical-edge.js +6 -64
- package/src/focusable.js +37 -32
- package/src/phrasing-content.js +1 -1
- package/src/tabbable.js +2 -4
- package/src/test/dom.js +8 -0
- package/tsconfig.tsbuildinfo +1 -1170
package/src/focusable.js
CHANGED
@@ -17,19 +17,32 @@
|
|
17
17
|
* - https://w3c.github.io/html/editing.html#data-model
|
18
18
|
*/
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
/**
|
21
|
+
* Returns a CSS selector used to query for focusable elements.
|
22
|
+
*
|
23
|
+
* @param {boolean} sequential If set, only query elements that are sequentially
|
24
|
+
* focusable. Non-interactive elements with a
|
25
|
+
* negative `tabindex` are focusable but not
|
26
|
+
* sequentially focusable.
|
27
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
28
|
+
*
|
29
|
+
* @return {string} CSS selector.
|
30
|
+
*/
|
31
|
+
function buildSelector( sequential ) {
|
32
|
+
return [
|
33
|
+
sequential ? '[tabindex]:not([tabindex^="-"])' : '[tabindex]',
|
34
|
+
'a[href]',
|
35
|
+
'button:not([disabled])',
|
36
|
+
'input:not([type="hidden"]):not([disabled])',
|
37
|
+
'select:not([disabled])',
|
38
|
+
'textarea:not([disabled])',
|
39
|
+
'iframe:not([tabindex^="-"])',
|
40
|
+
'object',
|
41
|
+
'embed',
|
42
|
+
'area[href]',
|
43
|
+
'[contenteditable]:not([contenteditable=false])',
|
44
|
+
].join( ',' );
|
45
|
+
}
|
33
46
|
|
34
47
|
/**
|
35
48
|
* Returns true if the specified element is visible (i.e. neither display: none
|
@@ -47,21 +60,6 @@ function isVisible( element ) {
|
|
47
60
|
);
|
48
61
|
}
|
49
62
|
|
50
|
-
/**
|
51
|
-
* Returns true if the specified element should be skipped from focusable elements.
|
52
|
-
* For now it rather specific for `iframes` and if tabindex attribute is set to -1.
|
53
|
-
*
|
54
|
-
* @param {Element} element DOM element to test.
|
55
|
-
*
|
56
|
-
* @return {boolean} Whether element should be skipped from focusable elements.
|
57
|
-
*/
|
58
|
-
function skipFocus( element ) {
|
59
|
-
return (
|
60
|
-
element.nodeName.toLowerCase() === 'iframe' &&
|
61
|
-
element.getAttribute( 'tabindex' ) === '-1'
|
62
|
-
);
|
63
|
-
}
|
64
|
-
|
65
63
|
/**
|
66
64
|
* Returns true if the specified area element is a valid focusable element, or
|
67
65
|
* false otherwise. Area is only focusable if within a map where a named map
|
@@ -88,18 +86,25 @@ function isValidFocusableArea( element ) {
|
|
88
86
|
/**
|
89
87
|
* Returns all focusable elements within a given context.
|
90
88
|
*
|
91
|
-
* @param {Element} context
|
89
|
+
* @param {Element} context Element in which to search.
|
90
|
+
* @param {Object} [options]
|
91
|
+
* @param {boolean} [options.sequential] If set, only return elements that are
|
92
|
+
* sequentially focusable.
|
93
|
+
* Non-interactive elements with a
|
94
|
+
* negative `tabindex` are focusable but
|
95
|
+
* not sequentially focusable.
|
96
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
92
97
|
*
|
93
98
|
* @return {Element[]} Focusable elements.
|
94
99
|
*/
|
95
|
-
export function find( context ) {
|
100
|
+
export function find( context, { sequential = false } = {} ) {
|
96
101
|
/* eslint-disable jsdoc/no-undefined-types */
|
97
102
|
/** @type {NodeListOf<HTMLElement>} */
|
98
103
|
/* eslint-enable jsdoc/no-undefined-types */
|
99
|
-
const elements = context.querySelectorAll(
|
104
|
+
const elements = context.querySelectorAll( buildSelector( sequential ) );
|
100
105
|
|
101
106
|
return Array.from( elements ).filter( ( element ) => {
|
102
|
-
if ( ! isVisible( element )
|
107
|
+
if ( ! isVisible( element ) ) {
|
103
108
|
return false;
|
104
109
|
}
|
105
110
|
|
package/src/phrasing-content.js
CHANGED
package/src/tabbable.js
CHANGED
@@ -181,10 +181,8 @@ export function findNext( element ) {
|
|
181
181
|
const focusables = findFocusable( element.ownerDocument.body );
|
182
182
|
const index = focusables.indexOf( element );
|
183
183
|
|
184
|
-
// Remove all focusables before and
|
185
|
-
const remaining = focusables
|
186
|
-
.slice( index + 1 )
|
187
|
-
.filter( ( node ) => ! element.contains( node ) );
|
184
|
+
// Remove all focusables before and including `element`.
|
185
|
+
const remaining = focusables.slice( index + 1 );
|
188
186
|
|
189
187
|
return first( filterTabbable( remaining ) );
|
190
188
|
}
|
package/src/test/dom.js
CHANGED
@@ -84,6 +84,14 @@ describe( 'DOM', () => {
|
|
84
84
|
expect( isHorizontalEdge( div, true ) ).toBe( true );
|
85
85
|
expect( isHorizontalEdge( div, false ) ).toBe( true );
|
86
86
|
} );
|
87
|
+
|
88
|
+
it( 'should return true for input types that do not have selection ranges', () => {
|
89
|
+
const input = document.createElement( 'input' );
|
90
|
+
input.setAttribute( 'type', 'checkbox' );
|
91
|
+
parent.appendChild( input );
|
92
|
+
expect( isHorizontalEdge( input, true ) ).toBe( true );
|
93
|
+
expect( isHorizontalEdge( input, false ) ).toBe( true );
|
94
|
+
} );
|
87
95
|
} );
|
88
96
|
|
89
97
|
describe( 'placeCaretAtHorizontalEdge', () => {
|