Changeset 56710 for trunk/src/wp-includes/blocks/search.php
- Timestamp:
- 09/26/2023 02:20:18 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/blocks/search.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/search.php
r56298 r56710 47 47 // Border color classes need to be applied to the elements that have a border color. 48 48 $border_color_classes = get_border_color_classes_for_block_core_search( $attributes ); 49 // This variable is a constant and its value is always false at this moment. 50 // It is defined this way because some values depend on it, in case it changes in the future. 51 $open_by_default = 'false'; 49 52 50 53 $label_inner_html = empty( $attributes['label'] ) ? __( 'Search' ) : wp_kses_post( $attributes['label'] ); … … 78 81 $is_expandable_searchfield = 'button-only' === $button_position && 'expand-searchfield' === $button_behavior; 79 82 if ( $is_expandable_searchfield ) { 83 $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.core.search.isSearchInputVisible' ); 84 $input->set_attribute( 'data-wp-bind--tabindex', 'selectors.core.search.tabindex' ); 85 // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core. 80 86 $input->set_attribute( 'aria-hidden', 'true' ); 81 87 $input->set_attribute( 'tabindex', '-1' ); … … 140 146 $button->add_class( implode( ' ', $button_classes ) ); 141 147 if ( 'expand-searchfield' === $attributes['buttonBehavior'] && 'button-only' === $attributes['buttonPosition'] ) { 148 $button->set_attribute( 'data-wp-bind--aria-label', 'selectors.core.search.ariaLabel' ); 149 $button->set_attribute( 'data-wp-bind--aria-controls', 'selectors.core.search.ariaControls' ); 150 $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.core.search.isSearchInputVisible' ); 151 $button->set_attribute( 'data-wp-bind--type', 'selectors.core.search.type' ); 152 $button->set_attribute( 'data-wp-on--click', 'actions.core.search.openSearchInput' ); 153 // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core. 142 154 $button->set_attribute( 'aria-label', __( 'Expand search field' ) ); 143 155 $button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id ); 144 156 $button->set_attribute( 'aria-expanded', 'false' ); 157 $button->set_attribute( 'type', 'button' ); 145 158 } else { 146 159 $button->set_attribute( 'aria-label', wp_strip_all_tags( $attributes['buttonText'] ) ); … … 159 172 array( 'class' => $classnames ) 160 173 ); 174 $form_directives = ''; 175 if ( $is_expandable_searchfield ) { 176 $aria_label_expanded = __( 'Submit Search' ); 177 $aria_label_collapsed = __( 'Expand search field' ); 178 $form_directives = ' 179 data-wp-interactive 180 data-wp-context=\'{ "core": { "search": { "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" } } }\' 181 data-wp-class--wp-block-search__searchfield-hidden="!context.core.search.isSearchInputVisible" 182 data-wp-on--keydown="actions.core.search.handleSearchKeydown" 183 data-wp-on--focusout="actions.core.search.handleSearchFocusout" 184 '; 185 } 161 186 162 187 return sprintf( 163 '<form role="search" method="get" action="% s" %s>%s</form>',188 '<form role="search" method="get" action="%1s" %2s %3s>%4s</form>', 164 189 esc_url( home_url( '/' ) ), 165 190 $wrapper_attributes, 191 $form_directives, 166 192 $label . $field_markup 167 193 ); … … 182 208 183 209 /** 210 * Ensure that the view script has the `wp-interactivity` dependency. 211 * 212 * @since 6.4.0 213 * 214 * @global WP_Scripts $wp_scripts 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'; 223 } 224 } 225 226 add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' ); 227 228 /** 184 229 * Builds the correct top level classnames for the 'core/search' block. 185 230 * … … 241 286 */ 242 287 function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) { 243 $is_button_inside = 'button-inside' === _wp_array_get( $attributes, array( 'buttonPosition' ), false );288 $is_button_inside = isset( $attributes['buttonPosition'] ) && 'button-inside' === $attributes['buttonPosition']; 244 289 245 290 $path = array( 'style', 'border', $property );
Note: See TracChangeset
for help on using the changeset viewer.