Skip to content

Commit

Permalink
Merge pull request #875 from vrk-kpa/fix/file-input-visibility
Browse files Browse the repository at this point in the history
[Fix] FileInput input-element visibility
  • Loading branch information
riitasointi authored Sep 11, 2024
2 parents b52f7a0 + 50fbd71 commit b984c39
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/Form/FileInput/FileInput.baseStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export const baseStyles = (
display: flex;
align-items: center;
&.fi-file-input_input-wrapper--hidden {
visibility: hidden;
}
.fi-file-input_drag-text-container {
${font(theme)('bodyTextSmall')}
margin-left: ${theme.spacing.insetXxl};
Expand Down
12 changes: 10 additions & 2 deletions src/core/Form/FileInput/FileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const fileInputClassNames = {
singleFileContainer: `${baseClassName}_single-file-container`,
multiFileContainer: `${baseClassName}_multi-file-container`,
inputWrapper: `${baseClassName}_input-wrapper`,
inputWrapperHidden: `${baseClassName}_input-wrapper--hidden`,
inputLabel: `${baseClassName}_input-label`,
inputElement: `${baseClassName}_input-element`,
error: `${baseClassName}--error`,
Expand Down Expand Up @@ -406,7 +407,9 @@ const BaseFileInput = (props: InternalFileInputProps) => {
// Handle focus
// If there is only one file, set focus to the input element
if (!multiFile || initialFilesArray.length === 1) {
inputRef.current?.focus();
setTimeout(() => {
inputRef.current?.focus();
}, 100);
} // In multi file mode, if the removed file was the first item, set focus to the next one
else if (indexOfRemovedFile === 0) {
fileItemRefs[indexOfRemovedFile + 1].fileNameRef.current?.focus();
Expand Down Expand Up @@ -504,7 +507,12 @@ const BaseFileInput = (props: InternalFileInputProps) => {
})}
forwardedRef={dragAreaRef}
>
<HtmlDiv className={fileInputClassNames.inputWrapper}>
<HtmlDiv
className={classnames(fileInputClassNames.inputWrapper, {
[fileInputClassNames.inputWrapperHidden]:
!multiFile && files && files.length > 0,
})}
>
<HtmlInput
id={id}
className={classnames(fileInputClassNames.inputElement, {
Expand Down
16 changes: 16 additions & 0 deletions src/core/Form/FileInput/__snapshots__/FileInput.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ exports[`snapshots match error status with statustext 1`] = `
align-items: center;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper.fi-file-input_input-wrapper--hidden {
visibility: hidden;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper .fi-file-input_drag-text-container {
-webkit-letter-spacing: 0;
-moz-letter-spacing: 0;
Expand Down Expand Up @@ -1174,6 +1178,10 @@ exports[`snapshots match hidden label 1`] = `
align-items: center;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper.fi-file-input_input-wrapper--hidden {
visibility: hidden;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper .fi-file-input_drag-text-container {
-webkit-letter-spacing: 0;
-moz-letter-spacing: 0;
Expand Down Expand Up @@ -1866,6 +1874,10 @@ exports[`snapshots match hint text 1`] = `
align-items: center;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper.fi-file-input_input-wrapper--hidden {
visibility: hidden;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper .fi-file-input_drag-text-container {
-webkit-letter-spacing: 0;
-moz-letter-spacing: 0;
Expand Down Expand Up @@ -2548,6 +2560,10 @@ exports[`snapshots match minimal implementation 1`] = `
align-items: center;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper.fi-file-input_input-wrapper--hidden {
visibility: hidden;
}
.c1.fi-file-input .fi-file-input_input-outer-wrapper .fi-file-input_drag-area .fi-file-input_input-wrapper .fi-file-input_drag-text-container {
-webkit-letter-spacing: 0;
-moz-letter-spacing: 0;
Expand Down

0 comments on commit b984c39

Please sign in to comment.