Skip to content

Commit 9724dab

Browse files
Block editor: [Backport] Make fit text work with the interativity API.
1 parent be6a610 commit 9724dab

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/wp-includes/block-supports/typography.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,20 @@ function wp_typography_get_preset_inline_style_value( $style_value, $css_propert
308308
function wp_render_typography_support( $block_content, $block ) {
309309
if ( ! empty( $block['attrs']['fitText'] ) && ! is_admin() ) {
310310
wp_enqueue_script_module( '@wordpress/block-editor/utils/fit-text-frontend' );
311+
312+
// Add Interactivity API directives for fit text to work with client-side navigation.
313+
if ( ! empty( $block_content ) ) {
314+
$processor = new WP_HTML_Tag_Processor( $block_content );
315+
if ( $processor->next_tag() ) {
316+
if ( ! $processor->get_attribute( 'data-wp-interactive' ) ) {
317+
$processor->set_attribute( 'data-wp-interactive', true );
318+
}
319+
$processor->set_attribute( 'data-wp-context---core-fit-text', 'core/fit-text::{"fontSize":""}' );
320+
$processor->set_attribute( 'data-wp-init---core-fit-text', 'core/fit-text::callbacks.init' );
321+
$processor->set_attribute( 'data-wp-style--font-size', 'core/fit-text::context.fontSize' );
322+
$block_content = $processor->get_updated_html();
323+
}
324+
}
311325
}
312326
if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) {
313327
return $block_content;

0 commit comments

Comments
 (0)