Repository navigation
Storybook: Add patterns for selecting local files - #86732
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: -788 B (-0.01%) Total Size: 8.73 MB 📦 View Changed
|
|
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 |
14ffb8e to
ab3f500
Compare
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.
Compare two layouts for long filenames with the current one: the type and size always below the name, or always on the name's first line with only the name wrapping. Remove the stories and the `layout` prop once a layout is chosen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every file row now has one layout: a 40px thumbnail, the name, and the type and size on a line below it. The thumbnail, the first line of the name, and the remove button line up at the top. A long name wraps and makes only its own row taller. Remove the temporary stories that compared layouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The button in the card's header pushed the title out of place. Put it in the empty state's actions, and below the list once fonts are added. The button now moves when the first font arrives or the last one goes, so render the change with `flushSync()` and focus the new button when the old one had focus.
…import Removing a cover image and retrying an upload moved focus before the change rendered, so the focused button still had its old name. Render the change with `flushSync()` first. When an import fails because the file can't be used, move focus to "Choose file…", as for any invalid field. Note in the docs that the server still checks every file.
…ames Each example decided on its own whether a change could rename the button that gets focus, and several missed one: the error description after an empty submit, the disabled state after a failed import, and "Add files" after the last removal. Render the change with `flushSync()` before every `focus()` call, and state that rule once in the checklist. Wrap filenames in `<bdi>`, so a name such as `123 - report.png` keeps its order on a right-to-left page. Note in the docs that the picker button doesn't repeat the fieldset's description, which the group already exposes.
A failed import moved focus to "Choose file…" even when people had moved on to another field while it ran. Move focus only if it's still where it was on submit; the live region still announces the error. In the docs, describe how `Fieldset` links its description instead of what screen readers do with it, say that a rejected replacement keeps the previous file, and drop a sentence about narrow upload rows that no longer matched the stacked layout.
… errors The fieldset's description holds the picker's requirements, such as the accepted types and limits, but it was linked only to the group. Give it an `id`, and list it in the picker button's `aria-describedby` before the error. Removing a file cleared the error, so the names of rejected files went away while people made room for them. Keep an error until the next file is added. Wrap filenames in error messages in Unicode isolates, as `<bdi>` does in the rows, so they keep their order on a right-to-left page.
…bels Adding the first font replaced the only text that listed the supported formats. List them below the button too, and link the text to the button in both states. `IconButton` shows its label in a tooltip, so a remove button's label mixed its filename with "Remove" on a right-to-left page. Isolate filenames in every string that is shown, as in errors.
023ac0b to
2f686c0
Compare
The checklist says to check every file's size, but both import examples read the whole file first. Check it against a 1 MB limit before the import reads it, and state the limit in the field's description. Note in the docs that `speak()` drops text that looks like an HTML tag, such as `<draft>` in a filename.
The import-on-choose example showed its 1 MB limit only after rejecting a file. Show it below the button and link it with `aria-describedby`. Reword the checklist so it asks for each field's own rules, as the examples check type everywhere and size or count only where a field limits them.
…er contrast Both import examples treated every failure as a bad file, so a failed request would ask for another file and move focus to the picker. Split the stand-in into `readPattern()` and `savePattern()`: a file that can't be read or isn't a pattern asks for another file, and a failed request keeps the file and asks people to try again. On hover, the picker's weaker text kept its resting color on the darker background, at 4.32:1. Use the matching `-active` token. Raise the preview snackbars' specificity with their own class, not with `.components-snackbar-list`, which belongs to the component.
…stale errors The picker said it used an outline `Button`'s tokens, but only switched background and stroke, and only on hover. Switch the foreground too, on hover, press, and focus, as `Button` does. Disabled weak text now uses its own `-weak-disabled` role. Filenames overrode `Text`'s `body-md` line height with `line-height-xs`, a pairing the type scale doesn't define. Keep `body-md`, and close the gap to the details below, so a one-line row keeps its height. Removing the chosen file from a single-file field now clears its error too, as the error was about that file. Lists still keep the names of rejected files while people make room. Import on choose keeps no file, so its failed-request error says to choose the file again.
|
@jameskoster "Choose files…" now sits in the empty state, and moves below the list once fonts are added. Focus follows it, so keyboard users don't lose their place. I also did a few more review rounds since your last look. The main changes are mostly to align those patterns with "first-party" |
jameskoster
left a comment
There was a problem hiding this comment.
I think we're good to go :)
|
The patterns are available at https://wordpress.github.io/gutenberg/?path=/docs/design-system-patterns-selecting-local-files--docs Happy to iterate in follow-up PRs if there's any remaining feedback. |





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,Text, andValidityIndicator.Button, including hover, press, and focus. The rows useCard's surface tokens, and all text usesTextvariants as they are.acceptonly filters the picker. It states its limits up front: the description is linked to the picker button witharia-describedby, before any error.flushSync()before it moves focus, so the focused button already has its new name, description, and state. Changes are announced withspeak().<bdi>in markup, and Unicode isolates in strings such as errors and tooltip labels.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, and "Choose files…" moves from the empty state to below the list, with the supported formats.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.speak()(@wordpress/a11y): it removes anything that looks like an HTML tag, so a filename such asreport <draft>.pdfis announced without<draft>. The page notes this limit.Storybook
Screenshots
Long names at 360px
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, GPT-6.2 Sol, and Claude Opus 5.5 found the accessibility, validation, token, layout, and right-to-left fixes in the later commits, and the follow-ups above.
🤖 Generated with Claude Code