Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global styles: improve Navigator usage in typography panel #65942

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function FontSize() {

const {
params: { origin, slug },
goTo,
goBack,
} = useNavigator();

const [ fontSizes, setFontSizes ] = useGlobalSetting(
Expand All @@ -53,10 +53,10 @@ function FontSize() {

// Navigate to the font sizes list if the font size is not available.
useEffect( () => {
if ( ! fontSize ) {
goTo( '/typography/font-sizes/', { isBack: true } );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using goTo here was hiding a bug, where goTo was being called twice. The fix is to also check for the slug, which then makes the code only run once

if ( !! slug && ! fontSize ) {
goBack();
}
}, [ fontSize, goTo ] );
}, [ slug, fontSize, goBack ] );

if ( ! origin || ! slug || ! fontSize ) {
return null;
Expand Down Expand Up @@ -158,7 +158,6 @@ function FontSize() {
__( 'Manage the font size %s.' ),
fontSize.name
) }
onBack={ () => goTo( '/typography/font-sizes/' ) }
/>
{ origin === 'custom' && (
<FlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function FontSizes() {
</HStack>
<ItemGroup isBordered isSeparated>
<NavigationButtonAsItem
path="/typography/font-sizes/"
path="/typography/font-sizes"
aria-label={ __( 'Edit font size presets' ) }
>
<HStack direction="row">
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function GlobalStylesUI() {
<ScreenTypography />
</GlobalStylesNavigationScreen>

<GlobalStylesNavigationScreen path="/typography/font-sizes/">
<GlobalStylesNavigationScreen path="/typography/font-sizes">
Copy link
Contributor Author

@ciampo ciampo Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trailing slash in the path was preventing Navigator from considering /typography/font-sizes/ as a valid parent screen to /typography/font-sizes/:origin/:slug when navigating back. Removing the trailing slack seems to fix the behavior

<FontSizes />
</GlobalStylesNavigationScreen>

Expand Down
Loading