Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Converted snippet preview mode buttons to radio buttons #376

Merged
merged 11 commits into from
Dec 17, 2019

Conversation

hwinne
Copy link
Contributor

@hwinne hwinne commented Oct 15, 2019

Summary

This issue has a PR in both the javascript and wordpress-seo repo.

Removed the mobile and desktop mode buttons, added radio buttons. Changed the title from Snippet Preview to Google search result preview (see Yoast/wordpress-seo#13649). Moved the buttons above the Snippet Preview.

This PR can be summarized in the following changelog entry:

  • [wordpress-seo] Enhances the Snippet Preview in the metabox by using radio buttons.
  • [@yoast/search-metadata-previews] Enhances the Snippet Editor's Mode Switcher component by using radio buttons.
  • [@yoast/components] Adds className attribute to the Input component.
  • [@yoast/components] Adds className and optionalAttributes attributes to the Label component.

Relevant technical choices:

  • Changed regular mode buttons to radio buttons
  • Moved mode buttons above the Snippet Preview
  • Changed the Snippet Preview Title (in ).

Test instructions

This PR can be tested by following these steps:

  • The snippet preview should look like the provided screenshots down below.
    • Test on all pages the Snippet Editor is used (such as: Posts, Pages, Tags, Categories, etc...)
  • The snipper preview should have the title "Google search result preview"
    • In the Metabox, under a post
    • In the Gutenberg sidebar menu.
    • In the Snippet Preview, when clicked from the Gutenberg sidebar menu.
  • The mobile/desktop mode should be toggled, when the radio buttons are toggled.

Screenshots

  • Under a post:
    image

  • In the Yoast sidebar in Gutenberg:
    image

  • When the Snippet Preview is accessed from the Yoast sidebar in Gutenberg:
    image

Impact check

  • This PR affects the following parts of the plugin, which may require extra testing:
    • Yoast Sidebar in the Gutenberg editor
    • Any page that uses the Snippet Preview in the Metabox

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Quality assurance

  • I have tested this code to the best of my abilities
  • I have added unittests to verify the code works as intended

Fixes #Yoast/wordpress-seo#13192

@hwinne hwinne added UI change PRs that result in a change in the UI Package: search-metadata-previews changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog labels Oct 15, 2019
@hwinne
Copy link
Contributor Author

hwinne commented Oct 15, 2019

🚧 The tests should be updated.

<SwitcherTitle>{ __( "Preview as", "yoast-components" ) + ":" }</SwitcherTitle>
<ModeLabel>
<ModeRadio
onChange={ () => onChange( MODE_MOBILE ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Pre-existing ESLint warning: JSX props should not use arrow functions

</ModeLabel>
<ModeLabel>
<ModeRadio
onChange={ () => onChange( MODE_DESKTOP ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Pre-existing ESLint warning: JSX props should not use arrow functions

@@ -528,6 +528,8 @@ class SnippetEditor extends React.Component {
return (
<ErrorBoundary>
<div>
<ModeSwitcher onChange={ ( newMode ) => onChange( "mode", newMode ) } active={ mode } />
Copy link
Contributor

Choose a reason for hiding this comment

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

Pre-existing ESLint warning: JSX props should not use arrow functions

const MobileButton = styled( SwitcherButton )`
border-radius: 3px 0 0 3px;
const ModeLabel = styled.label`
font: 400 14px/24px "Open Sans",sans-serif;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure we should use "Open Sans",sans-serif. Unless I'm missing something I think we normally use "font-family: inherit" and set the other values separately.

border-radius: 3px 0 0 3px;
const ModeLabel = styled.label`
font: 400 14px/24px "Open Sans",sans-serif;
margin-right: 18px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 18px? I guess this should use our 8 pixels grid thus 16px would be a better value.
More importantly: this needs to be reverted for RTL.

const DesktopButton = styled( SwitcherButton )`
border-radius: 0 3px 3px 0;
const ModeRadio = styled.input`
margin-right: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 10px? I guess this should use our 8 pixels grid thus 8px would be a better value.
More importantly: this needs to be reverted for RTL.

color: ${ colors.$color_snippet_focus };
box-shadow: none;
}
const Switcher = styled.div`
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a <fieldset> element to properly group the radio buttons.

border-radius: 4px;
background-color: #f7f7f7;
vertical-align: top;
const SwitcherTitle = styled.h4`
Copy link
Contributor

@afercia afercia Oct 28, 2019

Choose a reason for hiding this comment

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

This should be the <legend> of the <fieldset> element.
(Also, using a h4 skips one level within the meta box, as the previous heading is a h2)

</DesktopButton>
</Switcher>;
return ( <Switcher>
<SwitcherTitle>{ __( "Preview as", "yoast-components" ) + ":" }</SwitcherTitle>
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this + ":" pattern is used in a few other places but I'd reconsider it. What if other languages don't use colons? Translator wouldn't be able to remove it. I'd tend to think the colon should be part of the translatable string.

<ModeRadio
onChange={ () => onChange( MODE_MOBILE ) }
checked={ active === MODE_MOBILE }
aria-pressed={ active === MODE_MOBILE }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove aria-pressed: it was OK for the previous buttons but it's not appropriate for radio buttons.

<ModeRadio
onChange={ () => onChange( MODE_DESKTOP ) }
checked={ active === MODE_DESKTOP }
aria-pressed={ active === MODE_DESKTOP }
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove aria-pressed: it was OK for the previous buttons but it's not appropriate for radio buttons.

</Switcher>;
return ( <Switcher>
<SwitcherTitle>{ __( "Preview as", "yoast-components" ) + ":" }</SwitcherTitle>
<ModeLabel>
Copy link
Contributor

Choose a reason for hiding this comment

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

In other implementations we don't use wrapping labels. Instead, we use separate label and input, associated with for and id attributes. See for example the Configuration wizard. That's the recommended way to go as some assistive technologies don't work well with wrapping labels.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'd consider to use the existing Label component.

return ( <Switcher>
<SwitcherTitle>{ __( "Preview as", "yoast-components" ) + ":" }</SwitcherTitle>
<ModeLabel>
<ModeRadio
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd consider to use the existing Input component (see the Configuration wizard for usage example)

<span>{ __( "Mobile result", "yoast-components" ) }</span>
</ModeLabel>
<ModeLabel>
<ModeRadio
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above: consider to use the existing Label and Input components.

name="screen"
value="desktop"
/>
<span>{ __( "Desktop result", "yoast-components" ) }</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something and it actually serves some purpose, please remove this <span> element.

name="screen"
value="mobile"
/>
<span>{ __( "Mobile result", "yoast-components" ) }</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm missing something and it actually serves some purpose, please remove this <span> element.

font: 400 14px/24px "Open Sans",sans-serif;
margin-right: 18px;
cursor: pointer;
color: #3c4043;
Copy link
Contributor

Choose a reason for hiding this comment

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

This color is a Google color, only used for the snippet URL and the description. We shouldn't use it for our UI.

vertical-align: top;
const SwitcherTitle = styled.h4`
margin: .5em 0;
color: #3c4043;
Copy link
Contributor

Choose a reason for hiding this comment

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

This color is a Google color, only used for the snippet URL and the description. We shouldn't use it for our UI.

@afercia
Copy link
Contributor

afercia commented Oct 28, 2019

CR 🚧

Some considerations to address, see comments. Most notably:

  • styles for RTL
  • better semantics: group the radio buttons with fieldset + legend

@afercia
Copy link
Contributor

afercia commented Oct 28, 2019

Changes in the last commit:

  • used the existing Label and Input components
  • modified Label and Input to get the className passed by styled-components
  • please double check the change to Label optionalAttributes: may need adjustments
  • used a fieldset + legend elements to group the radio buttons
  • added styles for RTL

@afercia
Copy link
Contributor

afercia commented Oct 28, 2019

Note: RTL testing in the standalone demo appears to be broken for some reason.

Thus RTL needs to be tested directly in the plugin. Screenshots:

LTR:

Screenshot 2019-10-28 at 16 15 14

RTL:

Screenshot 2019-10-28 at 16 33 17

@afercia
Copy link
Contributor

afercia commented Oct 30, 2019

Note: very recent CSS changes in Gutenberg that were merged in WordPress core as part of the RC 3 broke the radio buttons layout within the meta boxes area. The radio buttons "blue dot" is now completely misplaced. See:

WordPress/gutenberg#18181
https://core.trac.wordpress.org/ticket/48466

This should be fixed upstream, hopefully as soon as possible because it's a regression in WP trunk.

@igorschoester
Copy link
Member

Acceptance 🚧

One error found:
When using the sidebar, the Google preview modal closes when you click on a radio button.

@hwinne
Copy link
Contributor Author

hwinne commented Dec 16, 2019

As Igor mentioned, the Google Preview modal closed when clicking the label of the radio button. I added onClick={ event.preventDefault } to the labels, so the label does not execute its default actions. @afercia could you please confirm this is the correct way of doing it?

When clicking the label it should still select the corresponding radio button.

When testing this, I had a strange bug where the fix would stay intact, even when I removed onClick={ event.preventDefault } (Meaning the modal would not close). Please make sure clicking the label will close the modal when removing said code.

Copy link
Contributor

@abotteram abotteram left a comment

Choose a reason for hiding this comment

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

CR 🚧

I don't know why the modal closes if you click the label, but this is not the right way to fix it I think.

@IreneStr
Copy link
Contributor

Acceptance 👍

@IreneStr IreneStr merged commit b6e4294 into develop Dec 17, 2019
@IreneStr IreneStr deleted the 13192-ux-improvements-to-snippet-preview branch December 17, 2019 15:00
@IreneStr IreneStr added this to the 12.9 milestone Dec 18, 2019
@afercia
Copy link
Contributor

afercia commented Dec 23, 2019

I don't know why the modal closes if you click the label, but this is not the right way to fix it I think.

Yeah, this happened (only in Chrome) because of the duplicate IDs and I guess the Gutenmodal "click outside" being triggered. Didn't happen on Firefox.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
changelog: enhancement Needs to be included in the 'Enhancements' category in the changelog Package: search-metadata-previews UI change PRs that result in a change in the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants