If we hide the HTML File Input element and customize its lable then when we test for keyboard accessibility check there is no focus border is coming
Although the file system window is opeining when we press keyboard’s tab and then enter but no indication on screen when the window is opening.
Is there any way to highlight or add focus to the input without showing it in the screen as it is hidden and the css is given to the input label. The functionality works fine but it fails when it comes to accessibility issue.
I have tried using position absolute like that but the its not working as the input is hidden and has no width and hight
Html
<form class="form" id="fileForm" enctype="multipart/form-data">
<label for="uploadButton" class="file__label">
upload File
</label>
<input type="file" accept="text/csv" id="uploadButton" name="fileInput" class="file__input">
</form>
css
.form {
width: 180px;
}
.form .file__label {
font-weight: normal;
cursor: pointer;
width: 180px;
vertical-align: middle;
text-align: center;
padding: 11px 0;
background-color: #ffffff;
color: #5e10b1;
border: 1px solid #5e10b1;
margin: 0;
}
.form .file__label:hover {
background-color: #f6f3f9;
outline: none;
border: 1px solid #5e10b1;
text-decoration: underline;
}
.form:focus {
outline: 0;
}
.form:focus .file__label {
outline: 2px solid #ffbf47;
}
.form .file__input {
height: 0;
width: 0;
overflow: hidden;
}