Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
66d0dbb
Expose state related to navigations
DAreRodz Jan 29, 2024
07bbaad
Remove loading bar and aria region from query block
DAreRodz Jan 29, 2024
e56191d
Implement wp-router-region processor
DAreRodz Jan 29, 2024
c2ab4d2
Remove aria regions and loading bar logic from query block
DAreRodz Jan 29, 2024
e0fecdc
Move loading bar CSS from query to router region processor
DAreRodz Jan 29, 2024
020e9c2
Recover `navigatingTo` variable
DAreRodz Jan 29, 2024
f45282b
Fix flaky test
DAreRodz Jan 29, 2024
2f95ca7
Remove unnecessary PHPUnit checks
DAreRodz Jan 29, 2024
eb65d2b
Ensure the callback is executed once
DAreRodz Feb 1, 2024
6ab84a1
Update boolean flags and message only if page exists
DAreRodz Feb 1, 2024
1c4445f
Clarify usage of unresolved promise
DAreRodz Feb 1, 2024
f207a79
More code reordering
DAreRodz Feb 1, 2024
56225f5
Save current link URL after navigating
DAreRodz Feb 1, 2024
04ce0dd
Add topLoadingBar and screenReaderAnnounce options
DAreRodz Feb 2, 2024
8217089
Fix url updating after navigating back or forward
DAreRodz Feb 2, 2024
196634c
Rename internal `url` variable to `pagePath`
DAreRodz Feb 2, 2024
4e7660f
Always set a string in `state.url`
DAreRodz Feb 2, 2024
ab00ba8
Remove confusing comment
DAreRodz Feb 2, 2024
1960203
Use internal state instance instead of `wp_interactivity_state`
DAreRodz Feb 2, 2024
a13b08c
Add id to the router animations style tag
DAreRodz Feb 2, 2024
9917541
Test the `data-wp-router-region` directive processor
DAreRodz Feb 2, 2024
e63e717
Rename topLoadingBar option to loadingAnimation
DAreRodz Feb 2, 2024
7d64b03
Update docs for options.loadingAnimation
DAreRodz Feb 2, 2024
bd3842c
Move router-region flag to the WP_Interactivity_API class
DAreRodz Feb 2, 2024
e08f981
Fix screenReaderAnnouncement name
DAreRodz Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement wp-router-region processor
  • Loading branch information
DAreRodz committed Jan 29, 2024
commit e56191df89bcc4c44d26e3aabec742c4b2944717
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class WP_Interactivity_API {
* @var array
*/
private static $directive_processors = array(
'data-wp-interactive' => 'data_wp_interactive_processor',
'data-wp-context' => 'data_wp_context_processor',
'data-wp-bind' => 'data_wp_bind_processor',
'data-wp-class' => 'data_wp_class_processor',
'data-wp-style' => 'data_wp_style_processor',
'data-wp-text' => 'data_wp_text_processor',
'data-wp-interactive' => 'data_wp_interactive_processor',
'data-wp-router-region' => 'data_wp_router_region_processor',
'data-wp-context' => 'data_wp_context_processor',
'data-wp-bind' => 'data_wp_bind_processor',
'data-wp-class' => 'data_wp_class_processor',
'data-wp-style' => 'data_wp_style_processor',
'data-wp-text' => 'data_wp_text_processor',
);

/**
Expand Down Expand Up @@ -673,6 +674,62 @@ private function data_wp_text_processor( WP_Interactivity_API_Directives_Process
}
}
}

/**
* Processes the `data-wp-router-region` directive.
*
* It renders in the footer a set of HTML elements to notify users about
* client-side navigations. More concretely, the elements added are 1) a
* top loading bar to visually inform that a navigation is in progress
* and 2) an `aria-live` region for accessible navigation announcements.
*
* The same action is registered everytime the directive is processed to
* prevent element duplication.
*
* @since 6.5.0
*
* @param WP_Interactivity_API_Directives_Processor $p The directives processor instance.
*/
private function data_wp_router_region_processor( WP_Interactivity_API_Directives_Processor $p ) {
if ( ! $p->is_tag_closer() ) {
/*
* The state could be declared multiple times here but is
* doesn't matter as the values are always the same.
*/
wp_interactivity_state(
'core/router',
array(
'navigation' => array(
'message' => '',
'hasStarted' => false,
'hasFinished' => false,
'texts' => array(
'loading' => __( 'Loading page, please wait.' ),
'loaded' => __( 'Page Loaded.' ),
),
),
)
);

$callback = static function () {
echo <<<HTML
<div
class="screen-reader-text"
aria-live="polite"
data-wp-interactive='{"namespace":"core/router"}'
data-wp-text="state.navigation.message"
></div>
<div
class="wp-block-query__enhanced-pagination-animation"
data-wp-interactive='{"namespace":"core/router"}'
data-wp-class--start-animation="state.navigation.hasStarted"
data-wp-class--finish-animation="state.navigation.hasFinished"
></div>
HTML;
};
add_action( 'wp_footer', $callback );
}
}
}

}