-
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
MediaPlaceholder: Fix media library button opening the file upload modal #34894
MediaPlaceholder: Fix media library button opening the file upload modal #34894
Conversation
I've added a few folks who've recently worked on the changed file as reviewers, but please let me know if there's anyone else I should ping instead 🙂 |
Size Change: -8 B (0%) Total Size: 1.06 MB
ℹ️ View Unchanged
|
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 tested well for me. I tested the Media placeholder with this patch in place against:
✅ Old gallery block
✅ New gallery block
✅ Individual image block
In each case clicking the Media Library
button open the media browser as expected with no upload dialog loading by default.
The file dialog still loaded as expected using the Select files
button in the Media library or the 'Upload' button on the Media placeholder.
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.
✅ From the placeholder state, click the Media library button — observe that the media library opens, but the file dialog does not
✅ Click elsewhere in the Placeholder — neither the media library nor the file dialog should open
✅ Click on the Upload button — the file dialog should open
I propose we remove the onClick handler on the overall Placeholder and move it down to the Upload button, to avoid unexpected behaviour.
I agree. Binding openFileDialog()
to the element that "opens the file dialog" make prima facie sense, and I think will avoid side effects in the future.
🚢
Description
Fixes #34099
This PR fixes an issue with the appender state of the MediaPlaceholder component where clicking the "Media library" button causes the file dialog modal to open. A common place to test this is with adding an image to a gallery that already has images.
Background on the issue
The regression appears to have been introduced in #33632 which removed the
event.stopPropagation()
call on themediaLibraryButton
so the click event bubbles up to the Placeholder component, which in theisAppender
state opens up the file dialog.Proposed fix
While we could re-instate the
event.stopPropagation()
call, I propose we remove theonClick
handler on the overall Placeholder and move it down to the Upload button, to avoid unexpected behaviour. This is just my personal preference of course, so happy for design feedback on this! CC: @jorgefilipecosta as it looks like the original behaviour was introduced back in #12367How has this been tested?
Manually in the editor. In looks like there were no other uses of the
onClick
param in therenderPlaceholder
function, but do let me know if you can think of any uses I've missed!Prior to applying this PR
After applying this PR
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).