Skip to content

Commit ace3376

Browse files
fix(file-uploader): use button for accessibility (#2351)
1 parent 7e5d437 commit ace3376

File tree

5 files changed

+11
-64
lines changed

5 files changed

+11
-64
lines changed

COMPONENT_INDEX.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,6 @@ None.
13161316
| disableLabelChanges | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable label changes |
13171317
| kind | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["kind"]</code> | <code>"primary"</code> | Specify the kind of file uploader button |
13181318
| size | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["size"]</code> | <code>"small"</code> | Specify the size of the file uploader button |
1319-
| role | No | <code>let</code> | No | <code>string</code> | <code>"button"</code> | Specify the label role |
1320-
| tabindex | No | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify `tabindex` attribute |
13211319
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the input element |
13221320
| name | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify a name attribute for the input |
13231321

docs/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/COMPONENT_API.json

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,30 +5158,6 @@
51585158
"constant": false,
51595159
"reactive": true
51605160
},
5161-
{
5162-
"name": "role",
5163-
"kind": "let",
5164-
"description": "Specify the label role",
5165-
"type": "string",
5166-
"value": "\"button\"",
5167-
"isFunction": false,
5168-
"isFunctionDeclaration": false,
5169-
"isRequired": false,
5170-
"constant": false,
5171-
"reactive": false
5172-
},
5173-
{
5174-
"name": "tabindex",
5175-
"kind": "let",
5176-
"description": "Specify `tabindex` attribute",
5177-
"type": "string",
5178-
"value": "\"0\"",
5179-
"isFunction": false,
5180-
"isFunctionDeclaration": false,
5181-
"isRequired": false,
5182-
"constant": false,
5183-
"reactive": false
5184-
},
51855161
{
51865162
"name": "id",
51875163
"kind": "let",
@@ -5237,7 +5213,7 @@
52375213
{
52385214
"type": "forwarded",
52395215
"name": "keydown",
5240-
"element": "label"
5216+
"element": "button"
52415217
},
52425218
{
52435219
"type": "forwarded",

src/FileUploader/FileUploaderButton.svelte

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@
3939
/** Specify the label text */
4040
export let labelText = "Add file";
4141
42-
/** Specify the label role */
43-
export let role = "button";
44-
45-
/** Specify `tabindex` attribute */
46-
export let tabindex = "0";
47-
4842
/** Set an id for the input element */
4943
export let id = "ccs-" + Math.random().toString(36);
5044
@@ -79,12 +73,10 @@
7973
}
8074
</script>
8175

82-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
83-
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
84-
<label
85-
aria-disabled={disabled}
86-
for={id}
87-
tabindex={disabled ? "-1" : tabindex}
76+
<button
77+
type="button"
78+
on:click={() => ref?.click()}
79+
{disabled}
8880
class:bx--btn={true}
8981
class:bx--btn--disabled={disabled}
9082
class:bx--btn--primary={kind === "primary"}
@@ -99,18 +91,11 @@
9991
class:bx--btn--lg={size === "lg"}
10092
class:bx--btn--xl={size === "xl"}
10193
on:keydown
102-
on:keydown={({ key }) => {
103-
if (key === " " || key === "Enter") {
104-
ref.click();
105-
}
106-
}}
10794
>
108-
<span {role}>
109-
<slot name="labelText">
110-
{labelText}
111-
</slot>
112-
</span>
113-
</label>
95+
<slot name="labelText">
96+
{labelText}
97+
</slot>
98+
</button>
11499
<input
115100
bind:this={ref}
116101
type="file"
@@ -120,6 +105,7 @@
120105
{id}
121106
{multiple}
122107
{name}
108+
aria-label={labelText}
123109
class:bx--visually-hidden={true}
124110
{...$$restProps}
125111
on:change|stopPropagation={({ target }) => {
@@ -133,6 +119,6 @@
133119
}}
134120
on:click
135121
on:click={({ target }) => {
136-
target.value = null;
122+
target.value = "";
137123
}}
138124
/>

types/FileUploader/FileUploaderButton.svelte.d.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ type $Props = {
5252
*/
5353
labelText?: string;
5454

55-
/**
56-
* Specify the label role
57-
* @default "button"
58-
*/
59-
role?: string;
60-
61-
/**
62-
* Specify `tabindex` attribute
63-
* @default "0"
64-
*/
65-
tabindex?: string;
66-
6755
/**
6856
* Set an id for the input element
6957
* @default "ccs-" + Math.random().toString(36)

0 commit comments

Comments
 (0)