-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
RichText: don't set focus when applying format #19536
Changes from all commits
401d949
540051f
d2905e4
8a1b782
c087194
da86012
daa575e
e7eeda3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,15 @@ export const bold = { | |
title, | ||
tagName: 'strong', | ||
className: null, | ||
edit( { isActive, value, onChange } ) { | ||
const onToggle = () => onChange( toggleFormat( value, { type: name } ) ); | ||
edit( { isActive, value, onChange, onFocus } ) { | ||
function onToggle() { | ||
onChange( toggleFormat( value, { type: name } ) ); | ||
} | ||
|
||
function onClick() { | ||
onToggle(); | ||
onFocus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is something that will impact third-party developers creating their own formats, I guess we should refer this PR in a dev note. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the label. It won't break anything, but yes it's a change in behaviour. :) |
||
} | ||
|
||
return ( | ||
<> | ||
|
@@ -27,7 +34,7 @@ export const bold = { | |
name="bold" | ||
icon="editor-bold" | ||
title={ title } | ||
onClick={ onToggle } | ||
onClick={ onClick } | ||
isActive={ isActive } | ||
shortcutType="primary" | ||
shortcutCharacter="b" | ||
|
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 sure about the name onFocus, it indicates that it is an event e.g: that we can pass something that is called when something gains focus, while what happens is that onFocus is a function that excitedly puts that focus back on rich text. Maybe we can call it "focus" or "focusRichText"?
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.
What's the difference with
onChange
? It's also not an event handler but rather an action to change something. I'd prefer to keep it consistent withonChange
, which is maybe also named poorly?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.
Cc @aduth since I know you have opinions about this. :)
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'd tend to agree with @jorgefilipecosta that the value of both
onChange
andonFocus
don't conform to my expectations, where my reading ofonFoo
would indicate some sort of event handler moreso than a "setter" as it seems to be used here. Then again, we don't usually pass around these functions, and in considering it as the function itself, it could be fine to allow it to represent something of a direct access to invoke the handler.For me, if it's meant to represent some sort of setter, I'd probably name it accordingly:
setValue
,setFocus
.If we're at a point where it's too late to change, I don't think it's worth stressing too much over. And I do think the consistency here is important, so even if we'd like
setFocus
, I think it's more important that it align toonChange
in at least being consistent with itself.