@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.
Files changed (58) hide show
  1. package/README.md +0 -1
  2. package/build/dom/caret-range-from-point.js +7 -3
  3. package/build/dom/caret-range-from-point.js.map +1 -1
  4. package/build/dom/is-edge.js +1 -1
  5. package/build/dom/is-edge.js.map +1 -1
  6. package/build/dom/place-caret-at-edge.js +108 -0
  7. package/build/dom/place-caret-at-edge.js.map +1 -0
  8. package/build/dom/place-caret-at-horizontal-edge.js +2 -84
  9. package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
  10. package/build/dom/place-caret-at-vertical-edge.js +6 -56
  11. package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
  12. package/build/focusable.js +29 -18
  13. package/build/focusable.js.map +1 -1
  14. package/build/phrasing-content.js +1 -1
  15. package/build/phrasing-content.js.map +1 -1
  16. package/build/tabbable.js +2 -2
  17. package/build/tabbable.js.map +1 -1
  18. package/build-module/dom/caret-range-from-point.js +7 -3
  19. package/build-module/dom/caret-range-from-point.js.map +1 -1
  20. package/build-module/dom/is-edge.js +1 -1
  21. package/build-module/dom/is-edge.js.map +1 -1
  22. package/build-module/dom/place-caret-at-edge.js +95 -0
  23. package/build-module/dom/place-caret-at-edge.js.map +1 -0
  24. package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
  25. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  26. package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
  27. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  28. package/build-module/focusable.js +29 -18
  29. package/build-module/focusable.js.map +1 -1
  30. package/build-module/phrasing-content.js +1 -1
  31. package/build-module/phrasing-content.js.map +1 -1
  32. package/build-module/tabbable.js +2 -2
  33. package/build-module/tabbable.js.map +1 -1
  34. package/build-types/dom/caret-range-from-point.d.ts +12 -4
  35. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  36. package/build-types/dom/is-edge.d.ts.map +1 -1
  37. package/build-types/dom/place-caret-at-edge.d.ts +9 -0
  38. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
  39. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  40. package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
  41. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  42. package/build-types/focusable.d.ts +11 -2
  43. package/build-types/focusable.d.ts.map +1 -1
  44. package/build-types/phrasing-content.d.ts +2 -4
  45. package/build-types/phrasing-content.d.ts.map +1 -1
  46. package/build-types/tabbable.d.ts +3 -3
  47. package/build-types/tabbable.d.ts.map +1 -1
  48. package/package.json +2 -2
  49. package/src/dom/caret-range-from-point.js +8 -3
  50. package/src/dom/is-edge.js +4 -1
  51. package/src/dom/place-caret-at-edge.js +95 -0
  52. package/src/dom/place-caret-at-horizontal-edge.js +2 -83
  53. package/src/dom/place-caret-at-vertical-edge.js +6 -64
  54. package/src/focusable.js +37 -32
  55. package/src/phrasing-content.js +1 -1
  56. package/src/tabbable.js +2 -4
  57. package/src/test/dom.js +8 -0
  58. 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
- const SELECTOR = [
21
- '[tabindex]',
22
- 'a[href]',
23
- 'button:not([disabled])',
24
- 'input:not([type="hidden"]):not([disabled])',
25
- 'select:not([disabled])',
26
- 'textarea:not([disabled])',
27
- 'iframe',
28
- 'object',
29
- 'embed',
30
- 'area[href]',
31
- '[contenteditable]:not([contenteditable=false])',
32
- ].join( ',' );
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 Element in which to search.
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( SELECTOR );
104
+ const elements = context.querySelectorAll( buildSelector( sequential ) );
100
105
 
101
106
  return Array.from( elements ).filter( ( element ) => {
102
- if ( ! isVisible( element ) || skipFocus( element ) ) {
107
+ if ( ! isVisible( element ) ) {
103
108
  return false;
104
109
  }
105
110
 
@@ -32,7 +32,7 @@ const textContentSchema = {
32
32
  s: {},
33
33
  del: {},
34
34
  ins: {},
35
- a: { attributes: [ 'href', 'target', 'rel' ] },
35
+ a: { attributes: [ 'href', 'target', 'rel', 'id' ] },
36
36
  code: {},
37
37
  abbr: { attributes: [ 'title' ] },
38
38
  sub: {},
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 inside `element`.
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', () => {