Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/file-preview/file-preview.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryFn } from '@storybook/react';
import { FilePreview, FilePreviewFile, FilePreviewProps } from './file-preview';
import { Input } from '@/index';
import { useState } from 'react';
import { useRef, useState } from 'react';

type InputValue = string | FileList | null;

Expand Down Expand Up @@ -65,6 +65,7 @@ DisabledState.args = {
};

export const FileInputWithPreview: Story = ( args ) => {
const fileInputRef = useRef<HTMLInputElement>( null );
const [ selectedFile, setSelectedFile ] = useState<File | null>( null );

const handleFileChange = ( value: InputValue ) => {
Expand All @@ -85,6 +86,7 @@ export const FileInputWithPreview: Story = ( args ) => {
return (
<>
<Input
ref={ fileInputRef }
label="Upload File"
type="file"
size="md"
Expand All @@ -97,7 +99,12 @@ export const FileInputWithPreview: Story = ( args ) => {
<FilePreview
{ ...args }
file={ selectedFile }
onRemove={ () => setSelectedFile( null ) }
onRemove={ () => {
setSelectedFile( null );
if ( fileInputRef.current ) {
fileInputRef.current.value = '';
}
} }
/>
</div>
) }
Expand Down
Loading