Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
BlockSettingsMenu: Ensure only one block settings menu is open at a time #54083
BlockSettingsMenu: Ensure only one block settings menu is open at a time #54083
Changes from 6 commits
e60376c
17d8e0a
5c9e6bd
ded5fcc
7ccdcf2
5c51724
c59e974
ba4579f
13c42ed
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
My only comment at this point is: wouldn't be simpler to always use
DropdownMenu
in a controlled way? Something likeI believe that the logic would just be simpler, and the behaviour of the
DropdownMenu
component more predictable (furthermore, React usually warns when this pattern is applied toinput
elements)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.
It'd be simpler in this component, but due to current usage of the BlockSettingsDropdown, a
currentClientId
isn't always available as ablock
object isn't always provided. So we currently need to support both controlled and uncontrolled in this component.In practice, at the moment, the List View provides a
block
object, however the block settings menu in the toolbar doesn't (it providesclientIds
for the selected blocks instead, which isn't quite the same as the concept of theblock
when used in the list view), so if we switch to always controlling the component, we wind up breaking the dropdown in the editor canvas:2023-09-13.10.34.46.mp4
Separately to this PR we could potentially look at refactoring other usage of the block settings dropdown to ensure a
block
object withclientId
is always provided, and then we could have the component always operate in controlled mode.For now, I'd prefer to try to contain the scope of this PR to the
BlockSettingsMenu
itself, so I think retaining this slightly complex ternary is probably a good step to go with for now, as it focuses on the main use case to solve which is with the behaviour in the list view.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.
This is the block of code that I'm suggesting to add some more comments about it being a temp solution..
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.
Do we really mean to have the default
clientId
as an empty string? I can see the action is set up to handle undefinedclientId
and the reducer will also return anull
, and those are all three different values representing "empty", which seems like an inconsistent behavior. Should we make it consistent and ultimately only go with either of them?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.
Did you mean
null
orundefined
? The default value isnull
and currently we'll returnundefined
if aclientId
is missing for some reason when dispatching thesetOpenedBlockSettingsMenu()
action (this feels like an inconsistent behavior on its own, so I'm commenting with it separately).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 block editor reducer is quite thoroughly covered by unit tests. A couple of simple tests could be useful to cover this new reducer subtree.
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.
For better precision, did we mean to return the default state of
null
instead ofundefined
in that scenario?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.
Oh, good call, that helps give this reducer consistency with other reducers that track a client id or null 👍