Skip to content

Commit 7cf4744

Browse files
authored
fix: Focus on file name after uploading a kubeconfig (#4081)
* fix: focus on file name * cleanup unused
1 parent 1cc5103 commit 7cf4744

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/shared/components/FileInput/FileInput.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { useRecoilValue } from 'recoil';
44

@@ -31,6 +31,7 @@ export function FileInput({
3131
const openAddCluster = useRecoilValue(showAddClusterWizard);
3232
const [draggingOverCounter, setDraggingCounter] = useState(0);
3333
const { t } = useTranslation();
34+
const fileNameRef = useRef(null);
3435

3536
useEffect(() => {
3637
if (!openAdd && !openAddCluster) setFileNames([]);
@@ -47,6 +48,12 @@ export function FileInput({
4748
if (files.length) {
4849
fileInputChanged(files);
4950
}
51+
52+
if (fileNameRef.current) {
53+
setTimeout(() => {
54+
fileNameRef.current?.focus();
55+
}, 50); // Timeout to ensure the focus is set after the DOM update
56+
}
5057
}
5158

5259
function drop(e) {
@@ -104,11 +111,12 @@ export function FileInput({
104111
{availableFormatsMessage && (
105112
<p className="file-input__secondary">{availableFormatsMessage}</p>
106113
)}
107-
{!!fileNames.length && (
108-
<p className="file-input__secondary">
109-
{`${fileNames.join(', ')} ${t('components.file-input.uploaded')}`}
110-
</p>
111-
)}
114+
115+
<p className="file-input__secondary" ref={fileNameRef} tabIndex={1}>
116+
{fileNames.length
117+
? `${fileNames.join(', ')} ${t('components.file-input.uploaded')}`
118+
: ''}
119+
</p>
112120
</div>
113121
</label>
114122
);

0 commit comments

Comments
 (0)