mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FileUpload: Fix showFileName option (#64202)
* FileUpload: Fix showFileName option * Fix tests
This commit is contained in:
@@ -30,7 +30,7 @@ describe('FileUpload', () => {
|
||||
const testFileName = 'grafana.png';
|
||||
const file = new File(['(⌐□_□)'], testFileName, { type: 'image/png' });
|
||||
const onFileUpload = jest.fn();
|
||||
const { getByTestId } = render(<FileUpload onFileUpload={onFileUpload} />);
|
||||
const { getByTestId } = render(<FileUpload onFileUpload={onFileUpload} showFileName={true} />);
|
||||
let uploader = getByTestId(selectors.components.FileUpload.inputField);
|
||||
await waitFor(() =>
|
||||
fireEvent.change(uploader, {
|
||||
@@ -45,7 +45,7 @@ describe('FileUpload', () => {
|
||||
const testFileName = 'longFileName.something.png';
|
||||
const file = new File(['(⌐□_□)'], testFileName, { type: 'image/png' });
|
||||
const onFileUpload = jest.fn();
|
||||
const { getByTestId } = render(<FileUpload onFileUpload={onFileUpload} />);
|
||||
const { getByTestId } = render(<FileUpload onFileUpload={onFileUpload} showFileName={true} />);
|
||||
let uploader = getByTestId(selectors.components.FileUpload.inputField);
|
||||
await waitFor(() =>
|
||||
fireEvent.change(uploader, {
|
||||
|
||||
@@ -31,6 +31,7 @@ export const FileUpload = ({
|
||||
children = 'Upload file',
|
||||
accept = '*',
|
||||
size = 'md',
|
||||
showFileName,
|
||||
}: React.PropsWithChildren<Props>) => {
|
||||
const style = useStyles2(getStyles(size));
|
||||
const [fileName, setFileName] = useState('');
|
||||
@@ -63,7 +64,7 @@ export const FileUpload = ({
|
||||
{children}
|
||||
</label>
|
||||
|
||||
{fileName && (
|
||||
{showFileName && fileName && (
|
||||
<span
|
||||
aria-label="File name"
|
||||
className={style.fileName}
|
||||
|
||||
Reference in New Issue
Block a user