wpseek.com
A WordPress-centric search engine for devs and theme authors
block_core_navigation_add_directives_to_submenu › WordPress Function
Since6.3.0
Deprecatedn/a
› block_core_navigation_add_directives_to_submenu ( $tags, $block_attributes )
Parameters: (2) |
|
Returns: |
|
Defined at: |
|
Codex: |
Add Interactivity API directives to the navigation-submenu and page-list blocks markup using the Tag Processor.
Source
function block_core_navigation_add_directives_to_submenu( $tags, $block_attributes ) { while ( $tags->next_tag( array( 'tag_name' => 'LI', 'class_name' => 'has-child', ) ) ) { // Add directives to the parent `<li>`. $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--keydown', 'actions.handleMenuKeydown' ); // This is a fix for Safari. Without it, Safari doesn't change the active // element when the user clicks on a button. It can be removed once we add // an overlay to capture the clicks, instead of relying on the focusout // event. $tags->set_attribute( 'tabindex', '-1' ); if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) { $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. if ( $tags->next_tag( array( 'tag_name' => 'BUTTON', 'class_name' => 'wp-block-navigation-submenu__toggle', ) ) ) { $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. } // Add directives to the submenu. if ( $tags->next_tag( array( 'tag_name' => 'UL', 'class_name' => 'wp-block-navigation__submenu-container', ) ) ) { $tags->set_attribute( 'data-wp-on-async--focus', 'actions.openMenuOnFocus' ); } // Iterate through subitems if exist. block_core_navigation_add_directives_to_submenu( $tags, $block_attributes ); } return $tags->get_updated_html(); }