Skip to content

Commit 8dcaa17

Browse files
committed
fix: improve progress bar accessibility, DRY, and edge cases
- Add ARIA attributes (role, aria-valuenow/min/max, aria-label) to progress bar - Extract clampedProgress and isError as shared @const declarations - Round percentage display to integer - Treat progress: 0 as pending instead of showing 0% - Replace dead button with plain Icon on success state - Remove redundant variant prop from percentage Text
1 parent 0197e8f commit 8dcaa17

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

v2/pink-sb/src/lib/upload/Box.svelte

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
<div transition:slide={{ axis: 'y', duration: 200 }}>
6969
{#each files as file}
7070
{@const fileSize = file?.size ? humanFileSize(file.size) : false}
71-
{@const hasProgress = typeof file?.progress === 'number'}
71+
{@const hasProgress = typeof file?.progress === 'number' && file.progress > 0}
72+
{@const clampedProgress = hasProgress
73+
? Math.round(Math.min(Math.max(file.progress ?? 0, 0), 100))
74+
: 0}
75+
{@const isError = !!file?.error || file?.status === 'failed'}
7276
<section>
7377
<Stack direction="column" gap="xs">
7478
<Stack
@@ -100,11 +104,9 @@
100104
</Stack>
101105
<Stack direction="row" gap="xxs" inline>
102106
{#if file?.status === 'success'}
103-
<Button variant="text" icon size="s">
104-
<Icon icon={IconCheck} color="--fgcolor-success" size="s" />
105-
</Button>
107+
<Icon icon={IconCheck} color="--fgcolor-success" size="s" />
106108
{:else}
107-
{#if file?.error}
109+
{#if isError}
108110
<Stack inline justifyContent="center">
109111
<Badge
110112
variant="secondary"
@@ -114,8 +116,8 @@
114116
/>
115117
</Stack>
116118
{:else if hasProgress}
117-
<Text color="--fgcolor-neutral-tertiary" variant="m-400">
118-
{Math.min(Math.max(file.progress ?? 0, 0), 100)}%
119+
<Text color="--fgcolor-neutral-tertiary">
120+
{clampedProgress}%
119121
</Text>
120122
{:else if file?.status === 'pending'}
121123
<Stack inline justifyContent="center">
@@ -147,11 +149,16 @@
147149
{#if hasProgress && file?.status !== 'success'}
148150
<div
149151
class="upload-progress-bar"
150-
class:is-error={!!file?.error || file?.status === 'failed'}
152+
class:is-error={isError}
153+
role="progressbar"
154+
aria-valuenow={clampedProgress}
155+
aria-valuemin={0}
156+
aria-valuemax={100}
157+
aria-label="{file.name} upload progress"
151158
>
152159
<div
153160
class="upload-progress-bar-fill"
154-
style="width: {Math.min(Math.max(file.progress ?? 0, 0), 100)}%"
161+
style="width: {clampedProgress}%"
155162
/>
156163
</div>
157164
{/if}

0 commit comments

Comments
 (0)