@wordpress/block-library 8.23.0 → 8.24.1
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/build/block/edit.js +8 -11
- package/build/block/edit.js.map +1 -1
- package/build/block/edit.native.js +3 -4
- package/build/block/edit.native.js.map +1 -1
- package/build/button/edit.js +4 -7
- package/build/button/edit.js.map +1 -1
- package/build/column/edit.js +1 -1
- package/build/column/edit.js.map +1 -1
- package/build/column/edit.native.js +1 -1
- package/build/column/edit.native.js.map +1 -1
- package/build/cover/edit/index.js +2 -1
- package/build/cover/edit/index.js.map +1 -1
- package/build/file/edit.js +8 -9
- package/build/file/edit.js.map +1 -1
- package/build/file/view.js +4 -6
- package/build/file/view.js.map +1 -1
- package/build/group/edit.js +3 -7
- package/build/group/edit.js.map +1 -1
- package/build/image/edit.js +17 -18
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +22 -15
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +35 -27
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +2 -3
- package/build/image/index.js.map +1 -1
- package/build/image/view.js +233 -268
- package/build/image/view.js.map +1 -1
- package/build/navigation/view.js +153 -176
- package/build/navigation/view.js.map +1 -1
- package/build/navigation-link/index.js +2 -1
- package/build/navigation-link/index.js.map +1 -1
- package/build/pattern/edit.js +1 -3
- package/build/pattern/edit.js.map +1 -1
- package/build/post-template/edit.js +1 -1
- package/build/post-template/edit.js.map +1 -1
- package/build/query/view.js +52 -60
- package/build/query/view.js.map +1 -1
- package/build/search/view.js +66 -74
- package/build/search/view.js.map +1 -1
- package/build/utils/remove-anchor-tag.js +17 -0
- package/build/utils/remove-anchor-tag.js.map +1 -0
- package/build-module/block/edit.js +8 -11
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/edit.native.js +3 -4
- package/build-module/block/edit.native.js.map +1 -1
- package/build-module/button/edit.js +4 -7
- package/build-module/button/edit.js.map +1 -1
- package/build-module/column/edit.js +1 -1
- package/build-module/column/edit.js.map +1 -1
- package/build-module/column/edit.native.js +1 -1
- package/build-module/column/edit.native.js.map +1 -1
- package/build-module/cover/edit/index.js +2 -1
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/file/edit.js +8 -9
- package/build-module/file/edit.js.map +1 -1
- package/build-module/file/view.js +5 -7
- package/build-module/file/view.js.map +1 -1
- package/build-module/group/edit.js +3 -7
- package/build-module/group/edit.js.map +1 -1
- package/build-module/image/edit.js +18 -19
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +23 -16
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +36 -28
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +2 -3
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/view.js +234 -269
- package/build-module/image/view.js.map +1 -1
- package/build-module/navigation/view.js +154 -177
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/navigation-link/index.js +2 -1
- package/build-module/navigation-link/index.js.map +1 -1
- package/build-module/pattern/edit.js +1 -3
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/post-template/edit.js +1 -1
- package/build-module/post-template/edit.js.map +1 -1
- package/build-module/query/view.js +53 -61
- package/build-module/query/view.js.map +1 -1
- package/build-module/search/view.js +67 -75
- package/build-module/search/view.js.map +1 -1
- package/build-module/utils/remove-anchor-tag.js +11 -0
- package/build-module/utils/remove-anchor-tag.js.map +1 -0
- package/build-style/cover/style-rtl.css +14 -14
- package/build-style/cover/style.css +14 -14
- package/build-style/editor-rtl.css +6 -9
- package/build-style/editor.css +6 -9
- package/build-style/gallery/style-rtl.css +28 -0
- package/build-style/gallery/style.css +28 -0
- package/build-style/image/editor-rtl.css +0 -3
- package/build-style/image/editor.css +0 -3
- package/build-style/style-rtl.css +42 -14
- package/build-style/style.css +42 -14
- package/package.json +32 -32
- package/src/block/edit.js +18 -19
- package/src/block/edit.native.js +5 -13
- package/src/button/edit.js +6 -6
- package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
- package/src/buttons/test/edit.native.js +0 -27
- package/src/column/edit.js +1 -1
- package/src/column/edit.native.js +1 -1
- package/src/cover/edit/index.js +1 -0
- package/src/cover/style.scss +1 -1
- package/src/cover/test/edit.js +1 -1
- package/src/editor.scss +6 -6
- package/src/file/edit.js +11 -10
- package/src/file/index.php +30 -11
- package/src/file/view.js +5 -7
- package/src/gallery/style.scss +1 -0
- package/src/group/edit.js +3 -11
- package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
- package/src/heading/test/index.native.js +40 -0
- package/src/image/block.json +2 -3
- package/src/image/edit.js +16 -21
- package/src/image/edit.native.js +17 -18
- package/src/image/editor.scss +0 -7
- package/src/image/image.js +48 -51
- package/src/image/index.php +54 -45
- package/src/image/view.js +278 -334
- package/src/navigation/index.php +19 -10
- package/src/navigation/view.js +159 -192
- package/src/navigation-link/block.json +2 -1
- package/src/paragraph/test/edit.native.js +37 -1
- package/src/pattern/edit.js +5 -3
- package/src/post-template/edit.js +1 -1
- package/src/query/index.php +36 -22
- package/src/query/view.js +58 -65
- package/src/query-pagination-next/index.php +3 -3
- package/src/query-pagination-numbers/index.php +1 -1
- package/src/query-pagination-previous/index.php +3 -3
- package/src/search/index.php +40 -40
- package/src/search/view.js +58 -63
- package/src/utils/remove-anchor-tag.js +10 -0
- package/tsconfig.json +1 -0
package/src/query/view.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
store,
|
|
6
|
+
getContext,
|
|
7
|
+
getElement,
|
|
8
|
+
navigate,
|
|
9
|
+
prefetch,
|
|
10
|
+
} from '@wordpress/interactivity';
|
|
5
11
|
|
|
6
12
|
const isValidLink = ( ref ) =>
|
|
7
13
|
ref &&
|
|
@@ -18,83 +24,70 @@ const isValidEvent = ( event ) =>
|
|
|
18
24
|
! event.shiftKey &&
|
|
19
25
|
! event.defaultPrevented;
|
|
20
26
|
|
|
21
|
-
store( {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
context.core.query.animation === 'finish',
|
|
29
|
-
},
|
|
27
|
+
store( 'core/query', {
|
|
28
|
+
state: {
|
|
29
|
+
get startAnimation() {
|
|
30
|
+
return getContext().animation === 'start';
|
|
31
|
+
},
|
|
32
|
+
get finishAnimation() {
|
|
33
|
+
return getContext().animation === 'finish';
|
|
30
34
|
},
|
|
31
35
|
},
|
|
32
36
|
actions: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
*navigate( event ) {
|
|
38
|
+
const ctx = getContext();
|
|
39
|
+
const { ref } = getElement();
|
|
40
|
+
const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
|
|
41
|
+
.wpNavigationDisabled;
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
isValidEvent( event ) &&
|
|
42
|
-
! isDisabled
|
|
43
|
-
) {
|
|
44
|
-
event.preventDefault();
|
|
43
|
+
if ( isValidLink( ref ) && isValidEvent( event ) && ! isDisabled ) {
|
|
44
|
+
event.preventDefault();
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const id = ref.closest( '[data-wp-navigation-id]' ).dataset
|
|
47
|
+
.wpNavigationId;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}, 400 );
|
|
49
|
+
// Don't announce the navigation immediately, wait 400 ms.
|
|
50
|
+
const timeout = setTimeout( () => {
|
|
51
|
+
ctx.message = ctx.loadingText;
|
|
52
|
+
ctx.animation = 'start';
|
|
53
|
+
}, 400 );
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
yield navigate( ref.href );
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
// Dismiss loading message if it hasn't been added yet.
|
|
58
|
+
clearTimeout( timeout );
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
context.core.query.loadedText
|
|
68
|
-
? '\u00A0'
|
|
69
|
-
: '' );
|
|
60
|
+
// Announce that the page has been loaded. If the message is the
|
|
61
|
+
// same, we use a no-break space similar to the @wordpress/a11y
|
|
62
|
+
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
|
|
63
|
+
ctx.message =
|
|
64
|
+
ctx.loadedText +
|
|
65
|
+
( ctx.message === ctx.loadedText ? '\u00A0' : '' );
|
|
70
66
|
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
ctx.animation = 'finish';
|
|
68
|
+
ctx.url = ref.href;
|
|
73
69
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
70
|
+
// Focus the first anchor of the Query block.
|
|
71
|
+
const firstAnchor = `[data-wp-navigation-id=${ id }] .wp-block-post-template a[href]`;
|
|
72
|
+
document.querySelector( firstAnchor )?.focus();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
*prefetch() {
|
|
76
|
+
const { ref } = getElement();
|
|
77
|
+
const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
|
|
78
|
+
.wpNavigationDisabled;
|
|
79
|
+
if ( isValidLink( ref ) && ! isDisabled ) {
|
|
80
|
+
yield prefetch( ref.href );
|
|
81
|
+
}
|
|
87
82
|
},
|
|
88
83
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
},
|
|
84
|
+
callbacks: {
|
|
85
|
+
*prefetch() {
|
|
86
|
+
const { url } = getContext();
|
|
87
|
+
const { ref } = getElement();
|
|
88
|
+
if ( url && isValidLink( ref ) ) {
|
|
89
|
+
yield prefetch( ref.href );
|
|
90
|
+
}
|
|
98
91
|
},
|
|
99
92
|
},
|
|
100
93
|
} );
|
|
@@ -72,9 +72,9 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
|
|
|
72
72
|
)
|
|
73
73
|
) ) {
|
|
74
74
|
$p->set_attribute( 'data-wp-key', 'query-pagination-next' );
|
|
75
|
-
$p->set_attribute( 'data-wp-on--click', '
|
|
76
|
-
$p->set_attribute( 'data-wp-on--mouseenter', '
|
|
77
|
-
$p->set_attribute( 'data-wp-
|
|
75
|
+
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
|
|
76
|
+
$p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
|
|
77
|
+
$p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
|
|
78
78
|
$content = $p->get_updated_html();
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -98,7 +98,7 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo
|
|
|
98
98
|
'class_name' => 'page-numbers',
|
|
99
99
|
)
|
|
100
100
|
) ) {
|
|
101
|
-
$p->set_attribute( 'data-wp-on--click', '
|
|
101
|
+
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
|
|
102
102
|
}
|
|
103
103
|
$content = $p->get_updated_html();
|
|
104
104
|
}
|
|
@@ -60,9 +60,9 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
|
|
|
60
60
|
)
|
|
61
61
|
) ) {
|
|
62
62
|
$p->set_attribute( 'data-wp-key', 'query-pagination-previous' );
|
|
63
|
-
$p->set_attribute( 'data-wp-on--click', '
|
|
64
|
-
$p->set_attribute( 'data-wp-on--mouseenter', '
|
|
65
|
-
$p->set_attribute( 'data-wp-
|
|
63
|
+
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
|
|
64
|
+
$p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
|
|
65
|
+
$p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
|
|
66
66
|
$content = $p->get_updated_html();
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/search/index.php
CHANGED
|
@@ -80,25 +80,35 @@ function render_block_core_search( $attributes, $content, $block ) {
|
|
|
80
80
|
|
|
81
81
|
$is_expandable_searchfield = 'button-only' === $button_position && 'expand-searchfield' === $button_behavior;
|
|
82
82
|
if ( $is_expandable_searchfield ) {
|
|
83
|
-
$input->set_attribute( 'data-wp-bind--aria-hidden', '!context.
|
|
84
|
-
$input->set_attribute( 'data-wp-bind--tabindex', '
|
|
83
|
+
$input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
|
|
84
|
+
$input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
|
|
85
85
|
// Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
|
|
86
86
|
$input->set_attribute( 'aria-hidden', 'true' );
|
|
87
87
|
$input->set_attribute( 'tabindex', '-1' );
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
$
|
|
92
|
-
|
|
93
|
-
$script_handles = $block->block_type->view_script_handles;
|
|
90
|
+
$is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
|
|
91
|
+
$script_handles = $block->block_type->view_script_handles;
|
|
92
|
+
$view_js_file = 'wp-block-search-view';
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
94
|
+
if ( $is_gutenberg_plugin ) {
|
|
95
|
+
if ( $is_expandable_searchfield ) {
|
|
96
|
+
gutenberg_enqueue_module( '@wordpress/block-library/search-block' );
|
|
98
97
|
}
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
// Remove the view script because we are using the module.
|
|
99
|
+
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
|
100
|
+
} else {
|
|
101
|
+
// If the script already exists, there is no point in removing it from viewScript.
|
|
102
|
+
if ( ! wp_script_is( $view_js_file ) ) {
|
|
103
|
+
|
|
104
|
+
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
105
|
+
if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) {
|
|
106
|
+
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
|
107
|
+
}
|
|
108
|
+
// If the script is needed, but it was previously removed, add it again.
|
|
109
|
+
if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) {
|
|
110
|
+
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
114
|
}
|
|
@@ -145,11 +155,11 @@ function render_block_core_search( $attributes, $content, $block ) {
|
|
|
145
155
|
if ( $button->next_tag() ) {
|
|
146
156
|
$button->add_class( implode( ' ', $button_classes ) );
|
|
147
157
|
if ( 'expand-searchfield' === $attributes['buttonBehavior'] && 'button-only' === $attributes['buttonPosition'] ) {
|
|
148
|
-
$button->set_attribute( 'data-wp-bind--aria-label', '
|
|
149
|
-
$button->set_attribute( 'data-wp-bind--aria-controls', '
|
|
150
|
-
$button->set_attribute( 'data-wp-bind--aria-expanded', 'context.
|
|
151
|
-
$button->set_attribute( 'data-wp-bind--type', '
|
|
152
|
-
$button->set_attribute( 'data-wp-on--click', 'actions.
|
|
158
|
+
$button->set_attribute( 'data-wp-bind--aria-label', 'state.ariaLabel' );
|
|
159
|
+
$button->set_attribute( 'data-wp-bind--aria-controls', 'state.ariaControls' );
|
|
160
|
+
$button->set_attribute( 'data-wp-bind--aria-expanded', 'context.isSearchInputVisible' );
|
|
161
|
+
$button->set_attribute( 'data-wp-bind--type', 'state.type' );
|
|
162
|
+
$button->set_attribute( 'data-wp-on--click', 'actions.openSearchInput' );
|
|
153
163
|
// Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
|
|
154
164
|
$button->set_attribute( 'aria-label', __( 'Expand search field' ) );
|
|
155
165
|
$button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id );
|
|
@@ -176,11 +186,11 @@ function render_block_core_search( $attributes, $content, $block ) {
|
|
|
176
186
|
$aria_label_expanded = __( 'Submit Search' );
|
|
177
187
|
$aria_label_collapsed = __( 'Expand search field' );
|
|
178
188
|
$form_directives = '
|
|
179
|
-
data-wp-interactive
|
|
180
|
-
data-wp-context=\'{ "
|
|
181
|
-
data-wp-class--wp-block-search__searchfield-hidden="!context.
|
|
182
|
-
data-wp-on--keydown="actions.
|
|
183
|
-
data-wp-on--focusout="actions.
|
|
189
|
+
data-wp-interactive=\'{ "namespace": "core/search" }\'
|
|
190
|
+
data-wp-context=\'{ "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" }\'
|
|
191
|
+
data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
|
|
192
|
+
data-wp-on--keydown="actions.handleSearchKeydown"
|
|
193
|
+
data-wp-on--focusout="actions.handleSearchFocusout"
|
|
184
194
|
';
|
|
185
195
|
}
|
|
186
196
|
|
|
@@ -203,27 +213,17 @@ function register_block_core_search() {
|
|
|
203
213
|
'render_callback' => 'render_block_core_search',
|
|
204
214
|
)
|
|
205
215
|
);
|
|
206
|
-
}
|
|
207
|
-
add_action( 'init', 'register_block_core_search' );
|
|
208
216
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
function block_core_search_ensure_interactivity_dependency() {
|
|
217
|
-
global $wp_scripts;
|
|
218
|
-
if (
|
|
219
|
-
isset( $wp_scripts->registered['wp-block-search-view'] ) &&
|
|
220
|
-
! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-search-view']->deps, true )
|
|
221
|
-
) {
|
|
222
|
-
$wp_scripts->registered['wp-block-search-view']->deps[] = 'wp-interactivity';
|
|
217
|
+
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
|
218
|
+
gutenberg_register_module(
|
|
219
|
+
'@wordpress/block-library/search-block',
|
|
220
|
+
gutenberg_url( '/build/interactivity/search.min.js' ),
|
|
221
|
+
array( '@wordpress/interactivity' ),
|
|
222
|
+
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
|
|
223
|
+
);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
|
-
|
|
226
|
-
add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' );
|
|
226
|
+
add_action( 'init', 'register_block_core_search' );
|
|
227
227
|
|
|
228
228
|
/**
|
|
229
229
|
* Builds the correct top level classnames for the 'core/search' block.
|
package/src/search/view.js
CHANGED
|
@@ -1,73 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store
|
|
4
|
+
import { store, getContext, getElement } from '@wordpress/interactivity';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
? '0'
|
|
30
|
-
: '-1';
|
|
31
|
-
},
|
|
32
|
-
},
|
|
6
|
+
const { actions } = store( 'core/search', {
|
|
7
|
+
state: {
|
|
8
|
+
get ariaLabel() {
|
|
9
|
+
const {
|
|
10
|
+
isSearchInputVisible,
|
|
11
|
+
ariaLabelCollapsed,
|
|
12
|
+
ariaLabelExpanded,
|
|
13
|
+
} = getContext();
|
|
14
|
+
return isSearchInputVisible
|
|
15
|
+
? ariaLabelExpanded
|
|
16
|
+
: ariaLabelCollapsed;
|
|
17
|
+
},
|
|
18
|
+
get ariaControls() {
|
|
19
|
+
const { isSearchInputVisible, inputId } = getContext();
|
|
20
|
+
return isSearchInputVisible ? null : inputId;
|
|
21
|
+
},
|
|
22
|
+
get type() {
|
|
23
|
+
const { isSearchInputVisible } = getContext();
|
|
24
|
+
return isSearchInputVisible ? 'submit' : 'button';
|
|
25
|
+
},
|
|
26
|
+
get tabindex() {
|
|
27
|
+
const { isSearchInputVisible } = getContext();
|
|
28
|
+
return isSearchInputVisible ? '0' : '-1';
|
|
33
29
|
},
|
|
34
30
|
},
|
|
35
31
|
actions: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
32
|
+
openSearchInput( event ) {
|
|
33
|
+
const ctx = getContext();
|
|
34
|
+
const { ref } = getElement();
|
|
35
|
+
if ( ! ctx.isSearchInputVisible ) {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
ctx.isSearchInputVisible = true;
|
|
38
|
+
ref.parentElement.querySelector( 'input' ).focus();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
closeSearchInput() {
|
|
42
|
+
const ctx = getContext();
|
|
43
|
+
ctx.isSearchInputVisible = false;
|
|
44
|
+
},
|
|
45
|
+
handleSearchKeydown( event ) {
|
|
46
|
+
const { ref } = getElement();
|
|
47
|
+
// If Escape close the menu.
|
|
48
|
+
if ( event?.key === 'Escape' ) {
|
|
49
|
+
actions.closeSearchInput();
|
|
50
|
+
ref.querySelector( 'button' ).focus();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
handleSearchFocusout( event ) {
|
|
54
|
+
const { ref } = getElement();
|
|
55
|
+
// If focus is outside search form, and in the document, close menu
|
|
56
|
+
// event.target === The element losing focus
|
|
57
|
+
// event.relatedTarget === The element receiving focus (if any)
|
|
58
|
+
// When focusout is outside the document,
|
|
59
|
+
// `window.document.activeElement` doesn't change.
|
|
60
|
+
if (
|
|
61
|
+
! ref.contains( event.relatedTarget ) &&
|
|
62
|
+
event.target !== window.document.activeElement
|
|
63
|
+
) {
|
|
64
|
+
actions.closeSearchInput();
|
|
65
|
+
}
|
|
71
66
|
},
|
|
72
67
|
},
|
|
73
68
|
} );
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes anchor tags from a string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} value The value to remove anchor tags from.
|
|
5
|
+
*
|
|
6
|
+
* @return {string} The value with anchor tags removed.
|
|
7
|
+
*/
|
|
8
|
+
export default function removeAnchorTag( value ) {
|
|
9
|
+
return value.replace( /<\/?a[^>]*>/g, '' );
|
|
10
|
+
}
|