@wordpress/block-library 8.18.0 → 8.19.0
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/CHANGELOG.md +2 -0
- package/README.md +1 -1
- package/build/block/edit.js +53 -2
- package/build/block/edit.js.map +1 -1
- package/build/button/edit.js +7 -4
- package/build/button/edit.js.map +1 -1
- package/build/button/index.js +11 -2
- package/build/button/index.js.map +1 -1
- package/build/button/save.js +10 -4
- package/build/button/save.js.map +1 -1
- package/build/buttons/edit.js +12 -3
- package/build/buttons/edit.js.map +1 -1
- package/build/code/edit.js +8 -2
- package/build/code/edit.js.map +1 -1
- package/build/code/index.js +7 -1
- package/build/code/index.js.map +1 -1
- package/build/column/edit.native.js +5 -5
- package/build/column/edit.native.js.map +1 -1
- package/build/column/index.js +1 -0
- package/build/column/index.js.map +1 -1
- package/build/columns/index.js +2 -0
- package/build/columns/index.js.map +1 -1
- package/build/file/edit.native.js +1 -1
- package/build/file/edit.native.js.map +1 -1
- package/build/file/index.js +2 -1
- package/build/file/index.js.map +1 -1
- package/build/file/utils/index.js +1 -15
- package/build/file/utils/index.js.map +1 -1
- package/build/file/view.js +14 -1
- package/build/file/view.js.map +1 -1
- package/build/footnotes/edit.js +14 -5
- package/build/footnotes/edit.js.map +1 -1
- package/build/gallery/edit.js +1 -1
- package/build/gallery/edit.js.map +1 -1
- package/build/group/edit.js +0 -1
- package/build/group/edit.js.map +1 -1
- package/build/group/index.js +5 -0
- package/build/group/index.js.map +1 -1
- package/build/heading/edit.js +0 -1
- package/build/heading/edit.js.map +1 -1
- package/build/heading/index.js +2 -0
- package/build/heading/index.js.map +1 -1
- package/build/heading/transforms.js +3 -6
- package/build/heading/transforms.js.map +1 -1
- package/build/image/deprecated.js +191 -7
- package/build/image/deprecated.js.map +1 -1
- package/build/image/edit.js +27 -12
- package/build/image/edit.js.map +1 -1
- package/build/image/image.js +75 -40
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +7 -4
- package/build/image/index.js.map +1 -1
- package/build/image/{view-interactivity.js → view.js} +1 -1
- package/build/image/view.js.map +1 -0
- package/build/list/deprecated.js +93 -1
- package/build/list/deprecated.js.map +1 -1
- package/build/list/edit.js +10 -10
- package/build/list/edit.js.map +1 -1
- package/build/list/ordered-list-settings.js +10 -10
- package/build/list/ordered-list-settings.js.map +1 -1
- package/build/list/save.js +4 -2
- package/build/list/save.js.map +1 -1
- package/build/list/utils.js +21 -2
- package/build/list/utils.js.map +1 -1
- package/build/navigation/constants.js +1 -1
- package/build/navigation/constants.js.map +1 -1
- package/build/navigation/index.js +4 -2
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/view.js +168 -82
- package/build/navigation/view.js.map +1 -1
- package/build/navigation-link/edit.js +3 -9
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/transforms.js +24 -0
- package/build/navigation-link/transforms.js.map +1 -1
- package/build/page-list/edit.js +2 -1
- package/build/page-list/edit.js.map +1 -1
- package/build/post-comments-form/edit.js +10 -2
- package/build/post-comments-form/edit.js.map +1 -1
- package/build/post-comments-form/form.js +5 -3
- package/build/post-comments-form/form.js.map +1 -1
- package/build/post-content/edit.js +8 -7
- package/build/post-content/edit.js.map +1 -1
- package/build/post-content/index.js +3 -0
- package/build/post-content/index.js.map +1 -1
- package/build/post-featured-image/overlay.js +2 -1
- package/build/post-featured-image/overlay.js.map +1 -1
- package/build/post-terms/use-post-terms.js +3 -2
- package/build/post-terms/use-post-terms.js.map +1 -1
- package/build/preformatted/edit.js +4 -1
- package/build/preformatted/edit.js.map +1 -1
- package/build/preformatted/index.js +1 -1
- package/build/preformatted/index.js.map +1 -1
- package/build/pullquote/deprecated.js +6 -7
- package/build/pullquote/deprecated.js.map +1 -1
- package/build/query/edit/enhanced-pagination-modal.js +56 -0
- package/build/query/edit/enhanced-pagination-modal.js.map +1 -0
- package/build/query/edit/inspector-controls/enhanced-pagination-control.js +42 -0
- package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
- package/build/query/edit/inspector-controls/index.js +8 -25
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/query-content.js +8 -2
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/utils.js +19 -0
- package/build/query/utils.js.map +1 -1
- package/build/query/view.js +4 -5
- package/build/query/view.js.map +1 -1
- package/build/search/index.js +1 -0
- package/build/search/index.js.map +1 -1
- package/build/search/view.js +81 -150
- package/build/search/view.js.map +1 -1
- package/build/social-link/edit.native.js +3 -1
- package/build/social-link/edit.native.js.map +1 -1
- package/build/table/edit.js +7 -7
- package/build/table/edit.js.map +1 -1
- package/build/table-of-contents/edit.js +2 -130
- package/build/table-of-contents/edit.js.map +1 -1
- package/build/table-of-contents/hooks.js +145 -0
- package/build/table-of-contents/hooks.js.map +1 -0
- package/build/table-of-contents/index.js +2 -1
- package/build/table-of-contents/index.js.map +1 -1
- package/build/verse/edit.js +4 -1
- package/build/verse/edit.js.map +1 -1
- package/build/verse/index.js +1 -1
- package/build/verse/index.js.map +1 -1
- package/build-module/block/edit.js +54 -3
- package/build-module/block/edit.js.map +1 -1
- package/build-module/button/edit.js +7 -4
- package/build-module/button/edit.js.map +1 -1
- package/build-module/button/index.js +11 -2
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/save.js +10 -4
- package/build-module/button/save.js.map +1 -1
- package/build-module/buttons/edit.js +12 -3
- package/build-module/buttons/edit.js.map +1 -1
- package/build-module/code/edit.js +8 -2
- package/build-module/code/edit.js.map +1 -1
- package/build-module/code/index.js +7 -1
- package/build-module/code/index.js.map +1 -1
- package/build-module/column/edit.native.js +5 -5
- package/build-module/column/edit.native.js.map +1 -1
- package/build-module/column/index.js +1 -0
- package/build-module/column/index.js.map +1 -1
- package/build-module/columns/index.js +2 -0
- package/build-module/columns/index.js.map +1 -1
- package/build-module/file/edit.native.js +1 -1
- package/build-module/file/edit.native.js.map +1 -1
- package/build-module/file/index.js +2 -1
- package/build-module/file/index.js.map +1 -1
- package/build-module/file/utils/index.js +0 -13
- package/build-module/file/utils/index.js.map +1 -1
- package/build-module/file/view.js +14 -2
- package/build-module/file/view.js.map +1 -1
- package/build-module/footnotes/edit.js +14 -5
- package/build-module/footnotes/edit.js.map +1 -1
- package/build-module/gallery/edit.js +1 -1
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/group/edit.js +0 -1
- package/build-module/group/edit.js.map +1 -1
- package/build-module/group/index.js +5 -0
- package/build-module/group/index.js.map +1 -1
- package/build-module/heading/edit.js +0 -1
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/heading/index.js +2 -0
- package/build-module/heading/index.js.map +1 -1
- package/build-module/heading/transforms.js +3 -6
- package/build-module/heading/transforms.js.map +1 -1
- package/build-module/image/deprecated.js +191 -7
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/edit.js +27 -12
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/image.js +77 -42
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +7 -4
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/{view-interactivity.js → view.js} +1 -1
- package/build-module/image/view.js.map +1 -0
- package/build-module/list/deprecated.js +95 -3
- package/build-module/list/deprecated.js.map +1 -1
- package/build-module/list/edit.js +10 -10
- package/build-module/list/edit.js.map +1 -1
- package/build-module/list/ordered-list-settings.js +10 -10
- package/build-module/list/ordered-list-settings.js.map +1 -1
- package/build-module/list/save.js +4 -2
- package/build-module/list/save.js.map +1 -1
- package/build-module/list/utils.js +20 -2
- package/build-module/list/utils.js.map +1 -1
- package/build-module/navigation/constants.js +1 -1
- package/build-module/navigation/constants.js.map +1 -1
- package/build-module/navigation/index.js +4 -2
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation/view.js +168 -83
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/navigation-link/edit.js +3 -9
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/transforms.js +24 -0
- package/build-module/navigation-link/transforms.js.map +1 -1
- package/build-module/page-list/edit.js +2 -1
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/post-comments-form/edit.js +10 -2
- package/build-module/post-comments-form/edit.js.map +1 -1
- package/build-module/post-comments-form/form.js +5 -3
- package/build-module/post-comments-form/form.js.map +1 -1
- package/build-module/post-content/edit.js +8 -7
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-content/index.js +3 -0
- package/build-module/post-content/index.js.map +1 -1
- package/build-module/post-featured-image/overlay.js +2 -1
- package/build-module/post-featured-image/overlay.js.map +1 -1
- package/build-module/post-terms/use-post-terms.js +3 -2
- package/build-module/post-terms/use-post-terms.js.map +1 -1
- package/build-module/preformatted/edit.js +4 -1
- package/build-module/preformatted/edit.js.map +1 -1
- package/build-module/preformatted/index.js +1 -1
- package/build-module/preformatted/index.js.map +1 -1
- package/build-module/pullquote/deprecated.js +6 -7
- package/build-module/pullquote/deprecated.js.map +1 -1
- package/build-module/query/edit/enhanced-pagination-modal.js +50 -0
- package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -0
- package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +35 -0
- package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -0
- package/build-module/query/edit/inspector-controls/index.js +9 -26
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/query-content.js +8 -2
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/utils.js +17 -0
- package/build-module/query/utils.js.map +1 -1
- package/build-module/query/view.js +4 -5
- package/build-module/query/view.js.map +1 -1
- package/build-module/search/index.js +1 -0
- package/build-module/search/index.js.map +1 -1
- package/build-module/search/view.js +81 -151
- package/build-module/search/view.js.map +1 -1
- package/build-module/social-link/edit.native.js +3 -1
- package/build-module/social-link/edit.native.js.map +1 -1
- package/build-module/table/edit.js +7 -7
- package/build-module/table/edit.js.map +1 -1
- package/build-module/table-of-contents/edit.js +3 -131
- package/build-module/table-of-contents/edit.js.map +1 -1
- package/build-module/table-of-contents/hooks.js +137 -0
- package/build-module/table-of-contents/hooks.js.map +1 -0
- package/build-module/table-of-contents/index.js +2 -1
- package/build-module/table-of-contents/index.js.map +1 -1
- package/build-module/verse/edit.js +4 -1
- package/build-module/verse/edit.js.map +1 -1
- package/build-module/verse/index.js +1 -1
- package/build-module/verse/index.js.map +1 -1
- package/build-style/cover/style-rtl.css +9 -0
- package/build-style/cover/style.css +9 -0
- package/build-style/editor-rtl.css +15 -9
- package/build-style/editor.css +15 -9
- package/build-style/file/style-rtl.css +5 -0
- package/build-style/file/style.css +5 -0
- package/build-style/heading/style-rtl.css +13 -0
- package/build-style/heading/style.css +13 -0
- package/build-style/navigation-link/editor-rtl.css +0 -9
- package/build-style/navigation-link/editor.css +0 -9
- package/build-style/paragraph/editor-rtl.css +5 -0
- package/build-style/paragraph/editor.css +5 -0
- package/build-style/paragraph/style-rtl.css +5 -0
- package/build-style/paragraph/style.css +5 -0
- package/build-style/post-navigation-link/style-rtl.css +3 -0
- package/build-style/post-navigation-link/style.css +3 -0
- package/build-style/query/editor-rtl.css +10 -0
- package/build-style/query/editor.css +10 -0
- package/build-style/query/style-rtl.css +1 -1
- package/build-style/query/style.css +1 -1
- package/build-style/reset-rtl.css +27 -27
- package/build-style/reset.css +27 -27
- package/build-style/style-rtl.css +35 -0
- package/build-style/style.css +35 -0
- package/package.json +32 -33
- package/src/audio/test/__snapshots__/edit.native.js.snap +78 -106
- package/src/avatar/index.php +2 -2
- package/src/block/edit.js +58 -2
- package/src/block/test/edit.native.js +2 -3
- package/src/button/block.json +11 -2
- package/src/button/edit.js +27 -11
- package/src/button/save.js +10 -4
- package/src/buttons/edit.js +13 -3
- package/src/buttons/test/edit.native.js +28 -24
- package/src/calendar/index.php +2 -2
- package/src/code/block.json +2 -1
- package/src/code/edit.js +13 -1
- package/src/code/index.js +5 -0
- package/src/column/block.json +1 -0
- package/src/column/edit.native.js +4 -4
- package/src/columns/block.json +2 -0
- package/src/columns/test/__snapshots__/edit.native.js.snap +14 -0
- package/src/columns/test/edit.native.js +47 -17
- package/src/comment-template/index.php +1 -1
- package/src/comments-pagination-next/index.php +1 -1
- package/src/comments-pagination-previous/index.php +1 -1
- package/src/cover/style.scss +12 -1
- package/src/cover/test/edit.js +7 -7
- package/src/cover/test/edit.native.js +18 -27
- package/src/embed/test/index.native.js +30 -45
- package/src/file/block.json +2 -1
- package/src/file/edit.native.js +1 -1
- package/src/file/index.php +19 -21
- package/src/file/style.scss +6 -1
- package/src/file/test/__snapshots__/edit.native.js.snap +162 -218
- package/src/file/utils/index.js +0 -15
- package/src/file/view.js +14 -5
- package/src/footnotes/edit.js +16 -2
- package/src/gallery/edit.js +1 -1
- package/src/gallery/index.php +1 -1
- package/src/group/block.json +5 -0
- package/src/group/edit.js +0 -1
- package/src/heading/block.json +2 -0
- package/src/heading/edit.js +0 -1
- package/src/heading/style.scss +4 -0
- package/src/heading/transforms.js +1 -6
- package/src/image/block.json +7 -4
- package/src/image/deprecated.js +210 -7
- package/src/image/edit.js +43 -29
- package/src/image/image.js +86 -43
- package/src/image/index.php +251 -28
- package/src/latest-posts/index.php +1 -1
- package/src/list/deprecated.js +84 -3
- package/src/list/edit.js +6 -3
- package/src/list/ordered-list-settings.js +20 -5
- package/src/list/save.js +10 -1
- package/src/list/test/edit.native.js +2 -4
- package/src/list/utils.js +22 -1
- package/src/navigation/block.json +4 -2
- package/src/navigation/constants.js +1 -0
- package/src/navigation/index.php +85 -123
- package/src/navigation/view.js +192 -96
- package/src/navigation-link/edit.js +21 -36
- package/src/navigation-link/editor.scss +0 -8
- package/src/navigation-link/transforms.js +22 -0
- package/src/page-list/edit.js +2 -1
- package/src/paragraph/editor.scss +5 -0
- package/src/paragraph/style.scss +5 -0
- package/src/pattern/index.php +2 -2
- package/src/post-comments-form/edit.js +10 -0
- package/src/post-comments-form/form.js +7 -1
- package/src/post-content/block.json +3 -0
- package/src/post-content/edit.js +14 -6
- package/src/post-excerpt/index.php +2 -2
- package/src/post-featured-image/index.php +2 -2
- package/src/post-featured-image/overlay.js +1 -0
- package/src/post-navigation-link/index.php +5 -1
- package/src/post-navigation-link/style.scss +4 -0
- package/src/post-template/index.php +1 -1
- package/src/post-terms/index.php +5 -2
- package/src/post-terms/use-post-terms.js +4 -2
- package/src/preformatted/edit.js +5 -0
- package/src/preformatted/index.js +1 -1
- package/src/pullquote/deprecated.js +8 -13
- package/src/query/edit/enhanced-pagination-modal.js +65 -0
- package/src/query/edit/inspector-controls/enhanced-pagination-control.js +49 -0
- package/src/query/edit/inspector-controls/index.js +9 -45
- package/src/query/edit/query-content.js +8 -0
- package/src/query/editor.scss +10 -0
- package/src/query/index.php +29 -16
- package/src/query/style.scss +2 -2
- package/src/query/utils.js +22 -0
- package/src/query/view.js +5 -5
- package/src/query-pagination-next/index.php +1 -1
- package/src/query-pagination-previous/index.php +1 -1
- package/src/reset.scss +1 -1
- package/src/search/block.json +1 -0
- package/src/search/index.php +45 -4
- package/src/search/test/__snapshots__/edit.native.js.snap +265 -363
- package/src/search/view.js +70 -169
- package/src/social-link/edit.native.js +1 -1
- package/src/social-link/editor.native.scss +4 -0
- package/src/table/edit.js +21 -19
- package/src/table-of-contents/block.json +2 -1
- package/src/table-of-contents/edit.js +5 -162
- package/src/table-of-contents/hooks.js +156 -0
- package/src/verse/edit.js +5 -0
- package/src/verse/index.js +1 -1
- package/src/verse/test/edit.native.js +2 -3
- package/build/file/view-interactivity.js +0 -22
- package/build/file/view-interactivity.js.map +0 -1
- package/build/image/view-interactivity.js.map +0 -1
- package/build/navigation/view-interactivity.js +0 -172
- package/build/navigation/view-interactivity.js.map +0 -1
- package/build/navigation/view-modal.js +0 -115
- package/build/navigation/view-modal.js.map +0 -1
- package/build-module/file/view-interactivity.js +0 -18
- package/build-module/file/view-interactivity.js.map +0 -1
- package/build-module/image/view-interactivity.js.map +0 -1
- package/build-module/navigation/view-interactivity.js +0 -169
- package/build-module/navigation/view-interactivity.js.map +0 -1
- package/build-module/navigation/view-modal.js +0 -112
- package/build-module/navigation/view-modal.js.map +0 -1
- package/src/file/view-interactivity.js +0 -18
- package/src/navigation/view-interactivity.js +0 -196
- package/src/navigation/view-modal.js +0 -127
- /package/src/image/{view-interactivity.js → view.js} +0 -0
package/src/navigation/index.php
CHANGED
|
@@ -67,99 +67,61 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) ) {
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
while ( $w->next_tag(
|
|
71
|
+
/**
|
|
72
|
+
* Add Interactivity API directives to the navigation-submenu and page-list
|
|
73
|
+
* blocks markup using the Tag Processor.
|
|
74
|
+
*
|
|
75
|
+
* @param string $w Markup of the navigation block.
|
|
76
|
+
* @param array $block_attributes Block attributes.
|
|
77
|
+
*
|
|
78
|
+
* @return string Submenu markup with the directives injected.
|
|
79
|
+
*/
|
|
80
|
+
function block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
|
|
81
|
+
while ( $w->next_tag(
|
|
82
|
+
array(
|
|
83
|
+
'tag_name' => 'LI',
|
|
84
|
+
'class_name' => 'has-child',
|
|
85
|
+
)
|
|
86
|
+
) ) {
|
|
87
|
+
// Add directives to the parent `<li>`.
|
|
88
|
+
$w->set_attribute( 'data-wp-interactive', true );
|
|
89
|
+
$w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
|
|
90
|
+
$w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
|
|
91
|
+
$w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
|
|
92
|
+
$w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
|
|
93
|
+
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
|
|
94
|
+
$w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
|
|
95
|
+
$w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Add directives to the toggle submenu button.
|
|
99
|
+
if ( $w->next_tag(
|
|
102
100
|
array(
|
|
103
|
-
'tag_name' => '
|
|
104
|
-
'class_name' => '
|
|
101
|
+
'tag_name' => 'BUTTON',
|
|
102
|
+
'class_name' => 'wp-block-navigation-submenu__toggle',
|
|
105
103
|
)
|
|
106
104
|
) ) {
|
|
107
|
-
|
|
108
|
-
$w->set_attribute( 'data-wp-
|
|
109
|
-
|
|
110
|
-
$w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
|
|
111
|
-
$w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
|
|
112
|
-
$w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
|
|
113
|
-
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
|
|
114
|
-
$w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
|
|
115
|
-
$w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Add directives to the toggle submenu button.
|
|
119
|
-
if ( $w->next_tag(
|
|
120
|
-
array(
|
|
121
|
-
'tag_name' => 'BUTTON',
|
|
122
|
-
'class_name' => 'wp-block-navigation-submenu__toggle',
|
|
123
|
-
)
|
|
124
|
-
) ) {
|
|
125
|
-
$w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
|
|
126
|
-
$w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// Add directives to the submenu.
|
|
130
|
-
if ( $w->next_tag(
|
|
131
|
-
array(
|
|
132
|
-
'tag_name' => 'UL',
|
|
133
|
-
'class_name' => 'wp-block-navigation__submenu-container',
|
|
134
|
-
)
|
|
135
|
-
) ) {
|
|
136
|
-
$w->set_attribute( 'data-wp-on--focusin', 'actions.core.navigation.openMenuOnFocus' );
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Iterate through subitems if exist.
|
|
140
|
-
block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
|
|
105
|
+
$w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
|
|
106
|
+
$w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
|
|
107
|
+
// The `aria-expanded` attribute for SSR is already added in the submenu block.
|
|
141
108
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* @return array Filtered block type metadata.
|
|
151
|
-
*/
|
|
152
|
-
function gutenberg_block_core_navigation_update_interactive_view_script( $metadata ) {
|
|
153
|
-
if ( 'core/navigation' === $metadata['name'] ) {
|
|
154
|
-
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
|
|
155
|
-
$metadata['supports']['interactivity'] = true;
|
|
109
|
+
// Add directives to the submenu.
|
|
110
|
+
if ( $w->next_tag(
|
|
111
|
+
array(
|
|
112
|
+
'tag_name' => 'UL',
|
|
113
|
+
'class_name' => 'wp-block-navigation__submenu-container',
|
|
114
|
+
)
|
|
115
|
+
) ) {
|
|
116
|
+
$w->set_attribute( 'data-wp-on--focus', 'actions.core.navigation.openMenuOnFocus' );
|
|
156
117
|
}
|
|
157
|
-
|
|
118
|
+
|
|
119
|
+
// Iterate through subitems if exist.
|
|
120
|
+
block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
|
|
158
121
|
}
|
|
159
|
-
|
|
122
|
+
return $w->get_updated_html();
|
|
160
123
|
}
|
|
161
124
|
|
|
162
|
-
|
|
163
125
|
/**
|
|
164
126
|
* Build an array with CSS classes and inline styles defining the colors
|
|
165
127
|
* which will be applied to the navigation markup in the front-end.
|
|
@@ -289,10 +251,6 @@ function block_core_navigation_render_submenu_icon() {
|
|
|
289
251
|
return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
|
|
290
252
|
}
|
|
291
253
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
254
|
/**
|
|
297
255
|
* Filter out empty "null" blocks from the block list.
|
|
298
256
|
* 'parse_blocks' includes a null block with '\n\n' as the content when
|
|
@@ -305,7 +263,7 @@ function block_core_navigation_render_submenu_icon() {
|
|
|
305
263
|
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
|
|
306
264
|
$filtered = array_filter(
|
|
307
265
|
$parsed_blocks,
|
|
308
|
-
static function( $block ) {
|
|
266
|
+
static function ( $block ) {
|
|
309
267
|
return isset( $block['blockName'] );
|
|
310
268
|
}
|
|
311
269
|
);
|
|
@@ -435,7 +393,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
435
393
|
// a fallback (i.e. the block has no menu associated with it).
|
|
436
394
|
$is_fallback = false;
|
|
437
395
|
|
|
438
|
-
$nav_menu_name = '';
|
|
396
|
+
$nav_menu_name = $attributes['ariaLabel'] ?? '';
|
|
439
397
|
|
|
440
398
|
/**
|
|
441
399
|
* Deprecated:
|
|
@@ -571,7 +529,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
571
529
|
}
|
|
572
530
|
|
|
573
531
|
// Manually add block support text decoration as CSS class.
|
|
574
|
-
$text_decoration =
|
|
532
|
+
$text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
|
|
575
533
|
$text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
|
|
576
534
|
|
|
577
535
|
$colors = block_core_navigation_build_css_colors( $attributes );
|
|
@@ -671,38 +629,25 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
671
629
|
$inner_blocks_html .= '</ul>';
|
|
672
630
|
}
|
|
673
631
|
|
|
674
|
-
$
|
|
675
|
-
|
|
676
|
-
'wp-block-navigation-view-2' => $is_responsive_menu,
|
|
677
|
-
);
|
|
678
|
-
|
|
679
|
-
$should_load_view_script = false;
|
|
680
|
-
if ( gutenberg_should_block_use_interactivity_api( 'core/navigation' ) ) {
|
|
681
|
-
// TODO: The script is still loaded even when it isn't needed when the Interactivity API is used.
|
|
682
|
-
$should_load_view_script = count( array_filter( $needed_script_map ) ) > 0;
|
|
683
|
-
} else {
|
|
684
|
-
foreach ( $needed_script_map as $view_script_handle => $is_view_script_needed ) {
|
|
685
|
-
|
|
686
|
-
// If the script already exists, there is no point in removing it from viewScript.
|
|
687
|
-
if ( wp_script_is( $view_script_handle ) ) {
|
|
688
|
-
continue;
|
|
689
|
-
}
|
|
632
|
+
$should_load_view_script = ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu;
|
|
633
|
+
$view_js_file = 'wp-block-navigation-view';
|
|
690
634
|
|
|
691
|
-
|
|
635
|
+
// If the script already exists, there is no point in removing it from viewScript.
|
|
636
|
+
if ( ! wp_script_is( $view_js_file ) ) {
|
|
637
|
+
$script_handles = $block->block_type->view_script_handles;
|
|
692
638
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
639
|
+
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
640
|
+
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
|
|
641
|
+
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
|
642
|
+
}
|
|
643
|
+
// If the script is needed, but it was previously removed, add it again.
|
|
644
|
+
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
|
|
645
|
+
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
|
701
646
|
}
|
|
702
647
|
}
|
|
703
648
|
|
|
704
649
|
// Add directives to the submenu if needed.
|
|
705
|
-
if (
|
|
650
|
+
if ( $has_submenus && $should_load_view_script ) {
|
|
706
651
|
$w = new WP_HTML_Tag_Processor( $inner_blocks_html );
|
|
707
652
|
$inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes );
|
|
708
653
|
}
|
|
@@ -750,7 +695,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
750
695
|
$responsive_container_directives = '';
|
|
751
696
|
$responsive_dialog_directives = '';
|
|
752
697
|
$close_button_directives = '';
|
|
753
|
-
if (
|
|
698
|
+
if ( $should_load_view_script ) {
|
|
754
699
|
$nav_element_directives = '
|
|
755
700
|
data-wp-interactive
|
|
756
701
|
data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\'
|
|
@@ -768,7 +713,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
768
713
|
tabindex="-1"
|
|
769
714
|
';
|
|
770
715
|
$responsive_dialog_directives = '
|
|
771
|
-
data-wp-bind--aria-modal="selectors.core.navigation.
|
|
716
|
+
data-wp-bind--aria-modal="selectors.core.navigation.ariaModal"
|
|
772
717
|
data-wp-bind--role="selectors.core.navigation.roleAttribute"
|
|
773
718
|
data-wp-effect="effects.core.navigation.focusFirstElement"
|
|
774
719
|
';
|
|
@@ -778,11 +723,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
778
723
|
}
|
|
779
724
|
|
|
780
725
|
$responsive_container_markup = sprintf(
|
|
781
|
-
'<button aria-haspopup="true" %3$s class="%6$s"
|
|
726
|
+
'<button aria-haspopup="true" %3$s class="%6$s" %11$s>%9$s</button>
|
|
782
727
|
<div class="%5$s" style="%7$s" id="%1$s" %12$s>
|
|
783
|
-
<div class="wp-block-navigation__responsive-close" tabindex="-1"
|
|
728
|
+
<div class="wp-block-navigation__responsive-close" tabindex="-1">
|
|
784
729
|
<div class="wp-block-navigation__responsive-dialog" aria-label="%8$s" %13$s>
|
|
785
|
-
<button %4$s
|
|
730
|
+
<button %4$s class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
|
|
786
731
|
<div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
|
|
787
732
|
%2$s
|
|
788
733
|
</div>
|
|
@@ -864,6 +809,23 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
|
|
|
864
809
|
|
|
865
810
|
add_filter( 'render_block_data', 'block_core_navigation_typographic_presets_backcompatibility' );
|
|
866
811
|
|
|
812
|
+
/**
|
|
813
|
+
* Ensure that the view script has the `wp-interactivity` dependency.
|
|
814
|
+
*
|
|
815
|
+
* @since 6.4.0
|
|
816
|
+
*/
|
|
817
|
+
function block_core_navigation_ensure_interactivity_dependency() {
|
|
818
|
+
global $wp_scripts;
|
|
819
|
+
if (
|
|
820
|
+
isset( $wp_scripts->registered['wp-block-navigation-view'] ) &&
|
|
821
|
+
! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-navigation-view']->deps, true )
|
|
822
|
+
) {
|
|
823
|
+
$wp_scripts->registered['wp-block-navigation-view']->deps[] = 'wp-interactivity';
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
add_action( 'wp_print_scripts', 'block_core_navigation_ensure_interactivity_dependency' );
|
|
828
|
+
|
|
867
829
|
/**
|
|
868
830
|
* Turns menu item data into a nested array of parsed blocks
|
|
869
831
|
*
|
|
@@ -957,7 +919,7 @@ function block_core_navigation_get_classic_menu_fallback() {
|
|
|
957
919
|
// Otherwise return the most recently created classic menu.
|
|
958
920
|
usort(
|
|
959
921
|
$classic_nav_menus,
|
|
960
|
-
static function( $a, $b ) {
|
|
922
|
+
static function ( $a, $b ) {
|
|
961
923
|
return $b->term_id - $a->term_id;
|
|
962
924
|
}
|
|
963
925
|
);
|
package/src/navigation/view.js
CHANGED
|
@@ -1,107 +1,203 @@
|
|
|
1
|
-
/*eslint-env browser*/
|
|
2
|
-
// Open on click functionality.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Keep track of whether a submenu is open to short-circuit delegated event listeners.
|
|
6
|
-
*
|
|
7
|
-
* @type {boolean}
|
|
8
|
-
*/
|
|
9
|
-
let hasOpenSubmenu = false;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Close submenu items for a navigation item.
|
|
13
|
-
*
|
|
14
|
-
* @param {HTMLElement} navigationItem - Either a NAV or LI element.
|
|
15
|
-
*/
|
|
16
|
-
function closeSubmenus( navigationItem ) {
|
|
17
|
-
navigationItem
|
|
18
|
-
.querySelectorAll( '[aria-expanded="true"]' )
|
|
19
|
-
.forEach( function ( toggle ) {
|
|
20
|
-
toggle.setAttribute( 'aria-expanded', 'false' );
|
|
21
|
-
} );
|
|
22
|
-
hasOpenSubmenu = false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
1
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param {HTMLButtonElement} buttonToggle
|
|
2
|
+
* WordPress dependencies
|
|
29
3
|
*/
|
|
30
|
-
|
|
31
|
-
const isSubmenuOpen =
|
|
32
|
-
buttonToggle.getAttribute( 'aria-expanded' ) === 'true';
|
|
33
|
-
const navigationItem = buttonToggle.closest( '.wp-block-navigation-item' );
|
|
4
|
+
import { store as wpStore } from '@wordpress/interactivity';
|
|
34
5
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.forEach( ( child ) => {
|
|
45
|
-
if ( child !== navigationItem ) {
|
|
46
|
-
closeSubmenus( child );
|
|
47
|
-
}
|
|
48
|
-
} );
|
|
6
|
+
const focusableSelectors = [
|
|
7
|
+
'a[href]',
|
|
8
|
+
'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
|
|
9
|
+
'select:not([disabled]):not([aria-hidden])',
|
|
10
|
+
'textarea:not([disabled]):not([aria-hidden])',
|
|
11
|
+
'button:not([disabled]):not([aria-hidden])',
|
|
12
|
+
'[contenteditable]',
|
|
13
|
+
'[tabindex]:not([tabindex^="-"])',
|
|
14
|
+
];
|
|
49
15
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
16
|
+
const openMenu = ( store, menuOpenedOn ) => {
|
|
17
|
+
const { context, ref, selectors } = store;
|
|
18
|
+
selectors.core.navigation.menuOpenedBy( store )[ menuOpenedOn ] = true;
|
|
19
|
+
context.core.navigation.previousFocus = ref;
|
|
20
|
+
if ( context.core.navigation.type === 'overlay' ) {
|
|
21
|
+
// Add a `has-modal-open` class to the <html> root.
|
|
22
|
+
document.documentElement.classList.add( 'has-modal-open' );
|
|
53
23
|
}
|
|
54
|
-
}
|
|
24
|
+
};
|
|
55
25
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
navigationBlocks.forEach( function ( block ) {
|
|
69
|
-
if ( ! block.contains( target ) ) {
|
|
70
|
-
closeSubmenus( block );
|
|
71
|
-
}
|
|
72
|
-
} );
|
|
26
|
+
const closeMenu = ( store, menuClosedOn ) => {
|
|
27
|
+
const { context, selectors } = store;
|
|
28
|
+
selectors.core.navigation.menuOpenedBy( store )[ menuClosedOn ] = false;
|
|
29
|
+
// Check if the menu is still open or not.
|
|
30
|
+
if ( ! selectors.core.navigation.isMenuOpen( store ) ) {
|
|
31
|
+
if (
|
|
32
|
+
context.core.navigation.modal?.contains(
|
|
33
|
+
window.document.activeElement
|
|
34
|
+
)
|
|
35
|
+
) {
|
|
36
|
+
context.core.navigation.previousFocus.focus();
|
|
73
37
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
38
|
+
context.core.navigation.modal = null;
|
|
39
|
+
context.core.navigation.previousFocus = null;
|
|
40
|
+
if ( context.core.navigation.type === 'overlay' ) {
|
|
41
|
+
document.documentElement.classList.remove( 'has-modal-open' );
|
|
78
42
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
82
45
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
46
|
+
wpStore( {
|
|
47
|
+
effects: {
|
|
48
|
+
core: {
|
|
49
|
+
navigation: {
|
|
50
|
+
initMenu: ( store ) => {
|
|
51
|
+
const { context, selectors, ref } = store;
|
|
52
|
+
if ( selectors.core.navigation.isMenuOpen( store ) ) {
|
|
53
|
+
const focusableElements =
|
|
54
|
+
ref.querySelectorAll( focusableSelectors );
|
|
55
|
+
context.core.navigation.modal = ref;
|
|
56
|
+
context.core.navigation.firstFocusableElement =
|
|
57
|
+
focusableElements[ 0 ];
|
|
58
|
+
context.core.navigation.lastFocusableElement =
|
|
59
|
+
focusableElements[ focusableElements.length - 1 ];
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
focusFirstElement: ( store ) => {
|
|
63
|
+
const { selectors, ref } = store;
|
|
64
|
+
if ( selectors.core.navigation.isMenuOpen( store ) ) {
|
|
65
|
+
ref.querySelector(
|
|
66
|
+
'.wp-block-navigation-item > *:first-child'
|
|
67
|
+
).focus();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
selectors: {
|
|
74
|
+
core: {
|
|
75
|
+
navigation: {
|
|
76
|
+
roleAttribute: ( store ) => {
|
|
77
|
+
const { context, selectors } = store;
|
|
78
|
+
return context.core.navigation.type === 'overlay' &&
|
|
79
|
+
selectors.core.navigation.isMenuOpen( store )
|
|
80
|
+
? 'dialog'
|
|
81
|
+
: null;
|
|
82
|
+
},
|
|
83
|
+
ariaModal: ( store ) => {
|
|
84
|
+
const { context, selectors } = store;
|
|
85
|
+
return context.core.navigation.type === 'overlay' &&
|
|
86
|
+
selectors.core.navigation.isMenuOpen( store )
|
|
87
|
+
? 'true'
|
|
88
|
+
: null;
|
|
89
|
+
},
|
|
90
|
+
isMenuOpen: ( { context } ) =>
|
|
91
|
+
// The menu is opened if either `click`, `hover` or `focus` is true.
|
|
92
|
+
Object.values(
|
|
93
|
+
context.core.navigation[
|
|
94
|
+
context.core.navigation.type === 'overlay'
|
|
95
|
+
? 'overlayOpenedBy'
|
|
96
|
+
: 'submenuOpenedBy'
|
|
97
|
+
]
|
|
98
|
+
).filter( Boolean ).length > 0,
|
|
99
|
+
menuOpenedBy: ( { context } ) =>
|
|
100
|
+
context.core.navigation[
|
|
101
|
+
context.core.navigation.type === 'overlay'
|
|
102
|
+
? 'overlayOpenedBy'
|
|
103
|
+
: 'submenuOpenedBy'
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
actions: {
|
|
109
|
+
core: {
|
|
110
|
+
navigation: {
|
|
111
|
+
openMenuOnHover( store ) {
|
|
112
|
+
const { navigation } = store.context.core;
|
|
113
|
+
if (
|
|
114
|
+
navigation.type === 'submenu' &&
|
|
115
|
+
// Only open on hover if the overlay is closed.
|
|
116
|
+
Object.values(
|
|
117
|
+
navigation.overlayOpenedBy || {}
|
|
118
|
+
).filter( Boolean ).length === 0
|
|
119
|
+
)
|
|
120
|
+
openMenu( store, 'hover' );
|
|
121
|
+
},
|
|
122
|
+
closeMenuOnHover( store ) {
|
|
123
|
+
closeMenu( store, 'hover' );
|
|
124
|
+
},
|
|
125
|
+
openMenuOnClick( store ) {
|
|
126
|
+
openMenu( store, 'click' );
|
|
127
|
+
},
|
|
128
|
+
closeMenuOnClick( store ) {
|
|
129
|
+
closeMenu( store, 'click' );
|
|
130
|
+
closeMenu( store, 'focus' );
|
|
131
|
+
},
|
|
132
|
+
openMenuOnFocus( store ) {
|
|
133
|
+
openMenu( store, 'focus' );
|
|
134
|
+
},
|
|
135
|
+
toggleMenuOnClick: ( store ) => {
|
|
136
|
+
const { selectors } = store;
|
|
137
|
+
const menuOpenedBy =
|
|
138
|
+
selectors.core.navigation.menuOpenedBy( store );
|
|
139
|
+
if ( menuOpenedBy.click || menuOpenedBy.focus ) {
|
|
140
|
+
closeMenu( store, 'click' );
|
|
141
|
+
closeMenu( store, 'focus' );
|
|
142
|
+
} else {
|
|
143
|
+
openMenu( store, 'click' );
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
handleMenuKeydown: ( store ) => {
|
|
147
|
+
const { context, selectors, event } = store;
|
|
148
|
+
if (
|
|
149
|
+
selectors.core.navigation.menuOpenedBy( store ).click
|
|
150
|
+
) {
|
|
151
|
+
// If Escape close the menu.
|
|
152
|
+
if ( event?.key === 'Escape' ) {
|
|
153
|
+
closeMenu( store, 'click' );
|
|
154
|
+
closeMenu( store, 'focus' );
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
91
157
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
158
|
+
// Trap focus if it is an overlay (main menu).
|
|
159
|
+
if (
|
|
160
|
+
context.core.navigation.type === 'overlay' &&
|
|
161
|
+
event.key === 'Tab'
|
|
162
|
+
) {
|
|
163
|
+
// If shift + tab it change the direction.
|
|
164
|
+
if (
|
|
165
|
+
event.shiftKey &&
|
|
166
|
+
window.document.activeElement ===
|
|
167
|
+
context.core.navigation
|
|
168
|
+
.firstFocusableElement
|
|
169
|
+
) {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
context.core.navigation.lastFocusableElement.focus();
|
|
172
|
+
} else if (
|
|
173
|
+
! event.shiftKey &&
|
|
174
|
+
window.document.activeElement ===
|
|
175
|
+
context.core.navigation.lastFocusableElement
|
|
176
|
+
) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
context.core.navigation.firstFocusableElement.focus();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
handleMenuFocusout: ( store ) => {
|
|
184
|
+
const { context, event } = store;
|
|
185
|
+
// If focus is outside modal, and in the document, close menu
|
|
186
|
+
// event.target === The element losing focus
|
|
187
|
+
// event.relatedTarget === The element receiving focus (if any)
|
|
188
|
+
// When focusout is outsite the document,
|
|
189
|
+
// `window.document.activeElement` doesn't change.
|
|
190
|
+
if (
|
|
191
|
+
! context.core.navigation.modal?.contains(
|
|
192
|
+
event.relatedTarget
|
|
193
|
+
) &&
|
|
194
|
+
event.target !== window.document.activeElement
|
|
195
|
+
) {
|
|
196
|
+
closeMenu( store, 'click' );
|
|
197
|
+
closeMenu( store, 'focus' );
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
105
202
|
},
|
|
106
|
-
|
|
107
|
-
);
|
|
203
|
+
} );
|