Skip to content

Commit

Permalink
Use data-wp-on-async directives when handler does not need synchronou…
Browse files Browse the repository at this point in the history
…s access to event
  • Loading branch information
westonruter committed May 31, 2024
1 parent 82e7b7a commit da7f0a8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
$close_button_directives = '';
if ( $is_interactive ) {
$open_button_directives = '
data-wp-on--click="actions.openMenuOnClick"
data-wp-on-async--click="actions.openMenuOnClick"
data-wp-on--keydown="actions.handleMenuKeydown"
';
$responsive_container_directives = '
data-wp-class--has-modal-open="state.isMenuOpen"
data-wp-class--is-menu-open="state.isMenuOpen"
data-wp-watch="callbacks.initMenu"
data-wp-on--keydown="actions.handleMenuKeydown"
data-wp-on--focusout="actions.handleMenuFocusout"
data-wp-on-async--focusout="actions.handleMenuFocusout"
tabindex="-1"
';
$responsive_dialog_directives = '
Expand All @@ -512,7 +512,7 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
data-wp-bind--role="state.roleAttribute"
';
$close_button_directives = '
data-wp-on--click="actions.closeMenuOnClick"
data-wp-on-async--click="actions.closeMenuOnClick"
';
$responsive_container_content_directives = '
data-wp-watch="callbacks.focusFirstElement"
Expand Down Expand Up @@ -826,7 +826,7 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
$tags->set_attribute( 'data-wp-interactive', 'core/navigation' );
$tags->set_attribute( 'data-wp-context', '{ "submenuOpenedBy": { "click": false, "hover": false, "focus": false }, "type": "submenu" }' );
$tags->set_attribute( 'data-wp-watch', 'callbacks.initMenu' );
$tags->set_attribute( 'data-wp-on--focusout', 'actions.handleMenuFocusout' );
$tags->set_attribute( 'data-wp-on-async--focusout', 'actions.handleMenuFocusout' );
$tags->set_attribute( 'data-wp-on--keydown', 'actions.handleMenuKeydown' );

// This is a fix for Safari. Without it, Safari doesn't change the active
Expand All @@ -836,8 +836,8 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
$tags->set_attribute( 'tabindex', '-1' );

if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
$tags->set_attribute( 'data-wp-on--mouseenter', 'actions.openMenuOnHover' );
$tags->set_attribute( 'data-wp-on--mouseleave', 'actions.closeMenuOnHover' );
$tags->set_attribute( 'data-wp-on-async--mouseenter', 'actions.openMenuOnHover' );
$tags->set_attribute( 'data-wp-on-async--mouseleave', 'actions.closeMenuOnHover' );
}

// Add directives to the toggle submenu button.
Expand All @@ -847,7 +847,7 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
'class_name' => 'wp-block-navigation-submenu__toggle',
)
) ) {
$tags->set_attribute( 'data-wp-on--click', 'actions.toggleMenuOnClick' );
$tags->set_attribute( 'data-wp-on-async--click', 'actions.toggleMenuOnClick' );
$tags->set_attribute( 'data-wp-bind--aria-expanded', 'state.isMenuOpen' );
// The `aria-expanded` attribute for SSR is already added in the submenu block.
}
Expand All @@ -858,7 +858,7 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
'class_name' => 'wp-block-navigation__submenu-container',
)
) ) {
$tags->set_attribute( 'data-wp-on--focus', 'actions.openMenuOnFocus' );
$tags->set_attribute( 'data-wp-on-async--focus', 'actions.openMenuOnFocus' );
}

// Iterate through subitems if exist.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const { state, actions } = store(
// If focus is outside modal, and in the document, close menu
// event.target === The element losing focus
// event.relatedTarget === The element receiving focus (if any)
// When focusout is outsite the document,
// When focusout is outside the document,
// `window.document.activeElement` doesn't change.

// The event.relatedTarget is null when something outside the navigation menu is clicked. This is only necessary for Safari.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/query-pagination-next/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
) ) {
$p->set_attribute( 'data-wp-key', 'query-pagination-next' );
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
$p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
$p->set_attribute( 'data-wp-on-async--mouseenter', 'core/query::actions.prefetch' );
$p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
$content = $p->get_updated_html();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
) ) {
$p->set_attribute( 'data-wp-key', 'query-pagination-previous' );
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
$p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
$p->set_attribute( 'data-wp-on-async--mouseenter', 'core/query::actions.prefetch' );
$p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
$content = $p->get_updated_html();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ function render_block_core_search( $attributes ) {
data-wp-interactive="core/search"'
. $form_context .
'data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
data-wp-on--keydown="actions.handleSearchKeydown"
data-wp-on--focusout="actions.handleSearchFocusout"
data-wp-on-async--keydown="actions.handleSearchKeydown"
data-wp-on-async--focusout="actions.handleSearchFocusout"
';
}

Expand Down

0 comments on commit da7f0a8

Please sign in to comment.