Repository navigation
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.73 MB
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Overlay menu interactions in Safari (@WebKit) in
|
|
Forgive me for missing something obvious, but is there a way we can vertically centre the "Choose Files" button in the InputControl variant? It looks broken as-is. Perhaps even some light styling of the button inside? |
|
Would a drag area example be good for "patterns"? 🤔 Visually it can differ a lot depending on specifics but there are UX and accessibility quirks that are probably worth documenting so that folks get those right. |
This is the key for me. IMO either we don't promote it, or we style it so it doesn't look broken. I don't have a strong opinion either way, so my instinct here is less against what Lena proposed, and more transversal. |
|
At this point in time, this PR was more of an experimentation to get alignment on the approach (hence the "technical example" wording). Happy to remove that "raw" input example from the patterns. Re. drag and drop, I've kept it out of this first iteration because base ui doesn't offer it (yet, it should be WIP). But I can look into it and see what we can do in the meantime. |
|
What I meant in the issue is that the file input will be visually hidden, therefore it itself doesn't need styling. I agree the docs should show styled patterns worth reusing, not raw examples that just show code-level composition. I also still think it's worth considering some kind of abstraction, rather than promote direct |
|
I audited the custom file inputs and
There is also a form with a visible, labeled file input and a separate Import button. That doesn't establish a new design requirement, but we should account for it before assuming inputs will always be hidden. I'm happy to remove the current visible Re. drag and drop, I can start from the existing The examples will / should cover keyboard access, consistent validation and disabled behavior, selection/error feedback, cancellation, and choosing the same file again. Re. having a visual component vs a hook, I guess that will depend on usage needs (@jasmussen also mentioned working on a related design) |
59e0c55 to
14ffb8e
Compare
|
Updated the PR as per the plan proposed above. |
|
Good links, @aduth . It feels like we should get a clear consensus on the file upload patterns that we want to support. I will then implement them as Storybook examples in this PR, and that should be a great starting point towards cleaning up / improving / standardising this pattern. @jasmussen / @jameskoster , happy to collaborate on those design specs! |
|
I'd love for us to at least loop in @lucyneb on design specs if possible, as there is some overlap with somthing she and Ann (AFK) have worked on. |
@jameskoster Oh ya, that's way better. Can you share the exact specs you used? whichever format, I'll incorporate into my latest designs. |
|
@lucyneb the specs could change during implementation, but it's basically a
We might end up with something more like this, especially if we want this control to share more DNA with others:
|
|
@jameskoster I added this style to my prototype, attaching screenshots. Do you think we should also consider adding a remove button? |
|
Yes I think that's a good idea. An |
`Fieldset.Root` now lets its content shrink (#87300), so the examples no longer need their own reset.
A cut filename can't be read in full on a touch screen, and two files with the same start look the same. Let the name wrap instead, with a tighter line height so a wrapped name reads as one item. When the type and size, or a status and its Retry button, don't fit beside the name, they move below it together. The picker button now builds its name from the text it shows, with a visually hidden "Replace" before it, so the type and size reach assistive technology. Keep the progress bar on whole pixels so every bar looks the same thickness, and keep the "Uploaded" note.
- Queue cancel and retry messages with the upload results, so a cancellation made right after adding a file is read last. - Give each file list an explicit list role. Safari drops it when the markers are hidden. - Let a long filename in an error message wrap, so the page doesn't scroll sideways at 320px.
The PNG and JSON fields accept a file by its MIME type or extension, as their `accept` attribute does. The stand-in importer now requires the same fields as the Patterns screen, so any other JSON file shows the error.
Only the first try for a PDF fails, so the caller can say so, and the upload no longer needs to store its attempt count.
Each entry gets its own ref when it's added, so the list examples no longer keep a map of buttons and a callback that fills it.
The type comes from the filename, so a long extension could still make the page scroll sideways.
Some images, such as HEIC photos, can't be shown in every browser. The row now falls back to the file icon instead of an empty thumbnail.
The stand-in importer now also rejects a non-string `syncStatus`, and lets `JSON.parse()` throw to the caller, which already shows the error.
A long confirmation grew upward from the bottom of a fixed frame and covered the Import button. In the page flow it can't, and the frame is no longer needed.
`DropZone` after `Card.Content` made the content a middle section, which has no bottom padding.
A state updater can run twice, so it shouldn't create IDs or refs.
A browser leaves the type empty when it can't tell what a file is. An image then still gets its thumbnail, and any other file falls back to the file icon.
If the remove button has focus when the import finishes, move focus to "Choose file…" before the row is removed.
Each example repeated the same live region and `ValidityIndicator`. `FilePickerError` keeps the region mounted, so a new message is still announced.
The drop area is a control, and surface tokens aren't for clickable parts. It now uses the neutral interactive tokens, like an input without a border, with matching hover and disabled states. The rows show chosen files, so they keep the surface tokens.
- Compare the drop area with an outline Button in the docs, which uses the same tokens, and drop a sentence that no longer holds. - Gray out a full or disabled drop area in forced-colors mode, as Button does, since it stays focusable. - Give text inside a picker button the button's weaker color. - Give the stand-in Media Library items their padding back and the same interactive tokens.
|
Thanks, @jameskoster ! I'd keep "Uploaded". The other cues are easy to miss if you look away, and a screen reader user going through the list later wouldn't hear the announcement again. It's also how you tell an uploaded file from one that's just chosen. To make room, rows now wrap instead of cutting the name. I also switched the drop area to the interactive tokens, like you suspected. Screenshots and follow-ups are in the description. I think this PR is now ready for an actual review @jameskoster @lucyneb @jasmussen @WordPress/gutenberg-components |





What?
See #84181. Related: #65333 and #76935.
Adds a Selecting Local Files pattern page to Storybook. It shows how to let people choose files with
FormFileUploadand@wordpress/ui: a drop area for one file, a list of several files, upload status, a panel that accepts dropped files, importing a file as soon as it's chosen, choosing a file for a form, and a menu with media sources.Why?
Gutenberg chooses files in several ways, often with its own
<input type="file">, and each screen solves focus, validation, and feedback on its own. The field design agreed on in this PR (James and Lucy) and Ann's prototype give one look for all of them, so the patterns can show it.How?
FormFileUploadand composes@wordpress/uicomponents:Fieldset,Button,IconButton,Menu,Dialog,Progress,Badge,Card,EmptyState, andValidityIndicator.Button. The rows show chosen files, so they use surface tokens.acceptonly filters the picker. It also announces changes withspeak()and moves focus to a sensible place after a removal or a retry.Testing Instructions
Open Design System → Patterns → Selecting Local Files in Storybook. For each example:
.ttfor.woff2file anywhere on the Fonts card. It's added to the list.Testing Instructions for Keyboard
Follow-ups
These came up while reviewing the examples. Each one belongs outside this PR.
Decisions for the UI package
aria-describedby, which is also how the@wordpress/uiform controls behave. Whether an identical, visible error should be announced again needs one decision across the package.accept.acceptonly filters the picker, so each example checks files again, by extension, by MIME type, or both. A file whose type the browser left empty, such as some PNGs, is then accepted by one example and rejected by another. One shared check belongs inFormFileUploador the file control planned in UI: Add a file input control #84181.Component bugs
Tooltip(@wordpress/ui): the popup has no maximum width or wrapping, so a remove button named after a long filename widens the page at 320px.Snackbar(@wordpress/components): a long unbroken word, such as a pattern title, widens the page at 320px.DropZone(@wordpress/components): when a drag carries both files and HTML, the overlay turns on only ifonHTMLDropis set, so a drop zone that takes only files ignores the drag. Its own comment says Windows Chrome sends both.Storybook
Screenshots
Long names: cut before, wrapped now
Drop area: rejected file, dragging, and disabled
Limits and upload status
Panel drop target
Import on choose, choose then submit, and media sources
Dark theme and right-to-left
Use of AI Tools
OpenAI Codex wrote the first version of the examples. Claude Code reworked them to match the shared designs, added the upload, import, panel, and media source examples, and captured the screenshots. Independent review rounds with GPT-6.2 Astra and Claude Opus 5.5 found the accessibility, validation, token, and layout fixes in the later commits, and the follow-ups above.
🤖 Generated with Claude Code