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

Add keyboard shortcut styling to "/" in default tip in the inserter modal #17222

Closed

Conversation

enriquesanchez
Copy link
Contributor

@enriquesanchez enriquesanchez commented Aug 27, 2019

Closes #17111

This PR adds keyboard shortcut styling to the "/" in the default tip in the inserter modal.

Before:
63377650-7e035300-c35e-11e9-9af5-6383f554b1fc

After:
Screen Shot 2019-08-27 at 3 11 01 PM

@enriquesanchez enriquesanchez changed the title Add keyboard shortcut styling to "/" in default tip Add keyboard shortcut styling to "/" in default tip in the inserter modal Aug 27, 2019
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Aug 27, 2019
@talldan talldan added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Enhancement A suggestion for improvement. labels Aug 28, 2019
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @enriquesanchez, this is something that makes complete sense and I'd really like to see merged!

Had a couple of comments, hopefully no major blockers if we can find a solution for the internationalisation.

'While writing, you can press "/" to quickly insert new blocks.'
'While writing, you can press'
) }
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key">/</kbd>
Copy link
Contributor

Choose a reason for hiding this comment

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

The class name applied here is from another component, which isn't really something encouraged as it can lead to maintainability issues (i.e. in the future someone changes the other component and doesn't realise this one will be affected).

I think there are three options:

  • Introduce a generic <Keyboard> react component in the @wordpress/components package that has this styling and can be use across the editor. There would have to be some thought about whether this is something wanted in that package.
  • Introduce some global styling for the kbd element or a mixin. Not sure about this option as I think it's nice to keep the global styling to a minimum and promote using components instead.
  • Duplicate some of the styles in tip component.

I think the third one might be preferable. As far as I know there are only two places in the codebase that have kbd styles. When there are three or four it might be time to consider refactoring to a component.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on that third option. Let's just duplicate the styles in this component for now.

If this comes up again we can explore one of the other two options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @talldan and @kjellr! Agree that option 3 sounds best. I'll push an update.

) }
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key">/</kbd>
{ __(
' to quickly insert new blocks.'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not completely sure of the best way to internationalise a string that has an HTML tag in it. Maybe using sprintf. I couldn't see any examples in the codebase. I'll ask for some feedback on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feedback on slack is here: https://wordpress.slack.com/archives/C02QB2JS7/p1566976018008100 (requires an account)

Seems as though splitting the string isn't a good idea, but there's no solution yet to internationalising text that has an html element in it. #16374 is a PR that attempts to address it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. it's very unfortunate that we can't use HTML tags inside translations as of today :(

@nerrad - how far did you get with your implementation for Interpolate component?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this definitely seems like something we should have a solution for. In the meantime, is this a blocker for the PR right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of any other way for accomplishing this but with some JS, and I'm not sure that would be desired here. Is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately I think it is a blocker. 😞

Unless there's a workaround I think it'll hold up the PR.

Copy link
Contributor

@nerrad nerrad Sep 1, 2019

Choose a reason for hiding this comment

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

Sorry for the delay here:

how far did you get with your implementation for Interpolate component?

In the pull I did, the more verbose createInterpolateElement can be extracted from that pull and released as is. It's usable and will solve the problem. I'm mostly waiting on a decision for whether that's a path we want to take initially.

However, the more intuitive jsx-like option with a <Translate> or <Interpolate/> component is not available yet (maybe could be done on a separate pull?).

Other than a brief discussion in a core-javascript slack chat, there hasn't been any feedback on the pull, so I've paused further work until it's clear it's a workable solution and we want to proceed with it.

Copy link
Member

Choose a reason for hiding this comment

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

I opened #18623 to add the same change but using the newly introduced API method.

@enriquesanchez
Copy link
Contributor Author

Closing because this PR is blocked until #16374 is merged.
Thanks everyone for the reviews! 👍

@gziolo gziolo deleted the add/keyboard-shortcut-style-to-default-tip branch September 3, 2019 14:46
@gziolo
Copy link
Member

gziolo commented Sep 3, 2019

We discussed this PR during the weekly Core JS chat today. @nerrad will work on createInterpolateComponent helper function which should help us unblock this PR. Related comment:
#16374 (comment)

Todo notes after slack chat

  • extract createInterpolateComponent to its own pull.
  • consider changing second argument to be an object instead of an array of arrays.
  • consider removing the necessity for a hasChildren key in the config (instead detecting via regex).

@talldan
Copy link
Contributor

talldan commented Dec 5, 2019

Looks like this is now unblocked with the __experimentalCreateInterpolateElement now merged to master.

@talldan
Copy link
Contributor

talldan commented Dec 5, 2019

@nerrad Would the correct usage be something like:

createInterpolateElement(
    __( 'While writing, you can press <kbd>/</kbd> to quickly insert new blocks' ),
    { kbd: <kbd /> }
);

@talldan
Copy link
Contributor

talldan commented Dec 5, 2019

Oh, just noticed this has already been handled in a separate PR, #18623. Ignore my above comments!

@gziolo
Copy link
Member

gziolo commented Dec 5, 2019

😄

There is an ongoing discussion whether <kbd>/<kbd> should be replaced with something else in the translations. I like the idea of having something like:

createInterpolateElement(
    __( 'While writing, you can press <SlashKey /> to quickly insert new blocks' ),
    { SlashKey: <kbd>/</kbd> }
);```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a "keyboard shortcut" treatment to the default tip in the inserter modal
5 participants