Skip to content

Commit c212899

Browse files
Adjust file upload file width (#1426)
## FileUpload - files width Removes implicit width from files in `<FileUpload>`. These now span the maximum width of the widest filename, while also respecting max-width of any container. Also changes alignment of the delete button for files in `<FileUpload>` from center to top. <img width="1538" height="485" alt="Screenshot 2025-09-23 at 14 42 45" src="https://github.com/user-attachments/assets/d62227fe-93ff-46e5-966a-13ac0df006e3" />
1 parent 626b651 commit c212899

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

.changeset/clean-dragons-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@obosbbl/grunnmuren-react": patch
3+
---
4+
5+
Changes alignment of the delete button for files in `<FileUpload>` from center to top.

.changeset/twenty-glasses-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@obosbbl/grunnmuren-react": patch
3+
---
4+
5+
Removes implicit width from files in `<FileUpload>`. These now span the maximum width of the widest filename, while also respecting max-width of any container.

packages/react/src/file-upload/file-upload.stories.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const meta: Meta<typeof FileUpload> = {
1313
},
1414
render: () => {
1515
return (
16-
<div className="p-4">
16+
<div className="container p-4">
1717
<FileUpload>
1818
<Label>Last opp fil</Label>
1919
<Description>Du kan laste opp én fil.</Description>
@@ -35,7 +35,7 @@ export const FileUploadStory: Story = {
3535
export const AllowsMultiple: Story = {
3636
render: () => {
3737
return (
38-
<div className="p-4">
38+
<div className="container p-4">
3939
<FileUpload allowsMultiple>
4040
<Label>Last opp filer</Label>
4141
<Description>
@@ -51,7 +51,7 @@ export const AllowsMultiple: Story = {
5151
export const LimitFileTypes: Story = {
5252
render: () => {
5353
return (
54-
<div className="p-4">
54+
<div className="w-72 max-w-full p-4">
5555
<FileUpload acceptedFileTypes={['.pdf']}>
5656
<Label>Last opp PDF</Label>
5757
<Description>Du kan kun laste opp én PDF.</Description>
@@ -65,7 +65,7 @@ export const LimitFileTypes: Story = {
6565
export const AcceptDirectory: Story = {
6666
render: () => {
6767
return (
68-
<div className="p-4">
68+
<div className="w-72 max-w-full p-4">
6969
<FileUpload acceptDirectory>
7070
<Label>Last opp mappe</Label>
7171
<Description>Du kan laste opp en mappe.</Description>
@@ -80,7 +80,7 @@ export const Controlled: Story = {
8080
render: () => {
8181
const [files, setFiles] = useState<File[]>([]);
8282
return (
83-
<div className="p-4">
83+
<div className="w-72 max-w-full p-4">
8484
<FileUpload files={files} onChange={setFiles} allowsMultiple>
8585
<Label>Last opp filer</Label>
8686
<Description>Du kan laste opp flere filer.</Description>
@@ -97,7 +97,7 @@ export const Required: Story = {
9797
return (
9898
<form
9999
encType="multipart/form-data"
100-
className="flex flex-col items-start gap-4 p-4"
100+
className="flex w-72 max-w-full flex-col items-start gap-4 p-4"
101101
onSubmit={(e) => {
102102
e.preventDefault();
103103
const formData = new FormData(e.target as HTMLFormElement);
@@ -126,7 +126,7 @@ export const Required: Story = {
126126
export const Validation: Story = {
127127
render: () => {
128128
return (
129-
<div className="p-4">
129+
<div className="w-72 max-w-full p-4">
130130
<FileUpload
131131
validate={(file) => file.size < 1000000 || 'Filen er for stor'}
132132
>
@@ -141,7 +141,7 @@ export const Validation: Story = {
141141

142142
export const InForm = () => (
143143
<form
144-
className="flex flex-col items-start gap-4 p-4"
144+
className="flex w-72 max-w-full flex-col items-start gap-4 p-4"
145145
encType="multipart/form-data"
146146
onSubmit={(e) => {
147147
e.preventDefault();

packages/react/src/file-upload/file-upload.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const FileUpload = ({
217217
<Provider values={[[FieldErrorContext, displayValidation]]}>
218218
<div
219219
data-slot="file-upload"
220-
className="group grid w-72 max-w-full gap-2"
220+
className="group grid gap-2"
221221
data-required={isRequired}
222222
>
223223
<Provider
@@ -273,7 +273,7 @@ const FileUpload = ({
273273
</FileTrigger>
274274
</Provider>
275275
{controlledOrUncontrolledFiles.length > 0 && (
276-
<ul className="mt-4 grid gap-y-2">
276+
<ul className="mt-4 grid max-w-fit gap-y-2">
277277
{controlledOrUncontrolledFiles.map((file, fileIndex) => {
278278
let fileName = file.name;
279279
if (
@@ -296,9 +296,10 @@ const FileUpload = ({
296296
: 'border-gray bg-gray-lightest',
297297
)}
298298
>
299-
{fileName}{' '}
299+
{fileName}
300300
<button
301301
className={cx(
302+
'self-start',
302303
'-m-2 grid h-11 w-11 shrink-0 cursor-pointer place-items-center rounded-xl',
303304
// Focus styles
304305
'focus-visible:-outline-offset-8 focus-visible:outline-focus',

0 commit comments

Comments
 (0)