-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
There was a problem hiding this 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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) } | ||
<kbd className="edit-post-keyboard-shortcut-help__shortcut-key">/</kbd> | ||
{ __( | ||
' to quickly insert new blocks.' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Closing because this PR is blocked until #16374 is merged. |
We discussed this PR during the weekly Core JS chat today. @nerrad will work on
|
Looks like this is now unblocked with the |
@nerrad Would the correct usage be something like: createInterpolateElement(
__( 'While writing, you can press <kbd>/</kbd> to quickly insert new blocks' ),
{ kbd: <kbd /> }
); |
Oh, just noticed this has already been handled in a separate PR, #18623. Ignore my above comments! |
😄 There is an ongoing discussion whether createInterpolateElement(
__( 'While writing, you can press <SlashKey /> to quickly insert new blocks' ),
{ SlashKey: <kbd>/</kbd> }
);``` |
Closes #17111
This PR adds keyboard shortcut styling to the "/" in the default tip in the inserter modal.
Before:
After: