Skip to content

Commit

Permalink
fix(input): fix accessibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dvcol committed Feb 10, 2025
1 parent a12c2c4 commit 5c73810
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 21 deletions.
3 changes: 3 additions & 0 deletions demo/components/DemoButtonGroups.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import NeoButtonGroup from '~/buttons/NeoButtonGroup.svelte';
import IconAccount from '~/icons/IconAccount.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import { displayValue } from '~/inputs/neo-select.model';
import { DefaultShadowElevation } from '~/utils/shadow.utils';
const { onClick, loading: loading$, onLoading } = useButtonState('DemoGroupClicked');
Expand Down Expand Up @@ -74,6 +75,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand Down
3 changes: 3 additions & 0 deletions demo/components/DemoButtons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import NeoSwitchButton from '~/buttons/NeoSwitchButton.svelte';
import IconAccount from '~/icons/IconAccount.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import { displayValue } from '~/inputs/neo-select.model';
const { onClick, loading: isLoading, onLoading } = useButtonState('DemoButtonClick');
Expand Down Expand Up @@ -94,6 +95,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand Down
3 changes: 3 additions & 0 deletions demo/components/DemoCards.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import NeoCard from '~/cards/NeoCard.svelte';
import NeoNumberStep from '~/inputs/NeoNumberStep.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import { displayValue } from '~/inputs/neo-select.model';
import NeoSkeletonMedia from '~/skeletons/NeoSkeletonMedia.svelte';
import NeoSkeletonText from '~/skeletons/NeoSkeletonText.svelte';
import { DefaultShadowElevation, getDefaultElevation, MaxShadowElevation, MinShadowElevation } from '~/utils/shadow.utils';
Expand Down Expand Up @@ -115,6 +116,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand Down
7 changes: 5 additions & 2 deletions demo/components/DemoInputs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand All @@ -577,7 +579,7 @@
{/snippet}

{#snippet after()}
<NeoButton text rounded={options.rounded} disabled={options.disabled} readonly={options.readonly}>
<NeoButton text aria-label="After button snippet" rounded={options.rounded} disabled={options.disabled} readonly={options.readonly}>
{#snippet icon()}
<IconFileUpload style="min-width: 1.25rem; min-height:1.25rem" />
{/snippet}
Expand Down Expand Up @@ -771,7 +773,6 @@
required
label="Custom Select"
placeholder="Select multiple"
display={displayValue}
options={items}
multiple
bind:ref={selectCustomMultipleState.ref}
Expand Down Expand Up @@ -1145,6 +1146,7 @@
{#snippet beforeRange()}
<NeoButton
rounded
aria-label="Increment range"
glass={options.glass}
disabled={options.disabled}
readonly={options.readonly}
Expand All @@ -1160,6 +1162,7 @@
{#snippet afterRange()}
<NeoButton
rounded
aria-label="Decrement range"
glass={options.glass}
disabled={options.disabled}
readonly={options.readonly}
Expand Down
3 changes: 3 additions & 0 deletions demo/components/DemoPill.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import IconMail from '~/icons/IconMail.svelte';
import NeoNumberStep from '~/inputs/NeoNumberStep.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import { displayValue } from '~/inputs/neo-select.model';
import NeoPill from '~/pill/NeoPill.svelte';
const options = $state({
Expand Down Expand Up @@ -97,6 +98,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
rounded={options.rounded}
Expand Down
3 changes: 3 additions & 0 deletions demo/components/DemoTabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import NeoButtonGroup from '~/buttons/NeoButtonGroup.svelte';
import IconAccount from '~/icons/IconAccount.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import { displayValue } from '~/inputs/neo-select.model';
import NeoTab from '~/nav/NeoTab.svelte';
import NeoTabDivider from '~/nav/NeoTabDivider.svelte';
import NeoTabs from '~/nav/NeoTabs.svelte';
Expand Down Expand Up @@ -119,6 +120,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand Down
3 changes: 3 additions & 0 deletions demo/components/DemoTooltips.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import NeoNumberStep from '~/inputs/NeoNumberStep.svelte';
import NeoSelect from '~/inputs/NeoSelect.svelte';
import NeoInput from '~/inputs/common/NeoInput.svelte';
import { displayValue } from '~/inputs/neo-select.model';
import NeoListBaseItem from '~/list/NeoListBaseItem.svelte';
import NeoPopSelect from '~/tooltips/NeoPopSelect.svelte';
import NeoTooltip from '~/tooltips/NeoTooltip.svelte';
Expand Down Expand Up @@ -155,6 +156,8 @@
placeholder="Select color"
position="left"
floating={false}
color={options.color}
display={displayValue}
size="10"
bind:value={options.color}
containerProps={{ style: 'margin-left: 6rem' }}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/inputs/NeoCheckbox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
}: NeoCheckboxProps = $props();
/* eslint-enable prefer-const */
const labelId = $derived(label ? `neo-checkbox-label-${getUUID()}` : undefined);
const elevation = $derived(coerce(rest?.elevation ?? DefaultShadowShallowElevation));
let initial = $state(checked);
Expand Down Expand Up @@ -172,6 +173,7 @@
class={['neo-checkbox-input', rest.class]}
/>
<NeoCheckboxButton
aria-labelledby={labelId}
{indeterminate}
{checked}
{touched}
Expand All @@ -186,7 +188,7 @@
onclick={() => ref?.click()}
{...buttonProps}
/>
<NeoLabel bind:ref={labelRef} for={id} {label} {disabled} {required} {...labelProps} />
<NeoLabel bind:ref={labelRef} id={labelId} for={id} {label} {disabled} {required} {...labelProps} />
{#if loading !== undefined}
<span class="neo-checkbox-suffix">
{#if loading}
Expand Down
6 changes: 6 additions & 0 deletions src/lib/inputs/NeoColorPicker.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { getUUID } from '@dvcol/common-utils/common/string';
import type { FormEventHandler } from 'svelte/elements';
import type { NeoButtonProps } from '~/buttons/neo-button.model.js';
Expand Down Expand Up @@ -74,12 +76,15 @@
ref?.dispatchEvent(new InputEvent(e.type, e));
pickerProps?.onchange?.(e);
};
const labelId = $derived(rest?.label ? `neo-color-picker-label-${getUUID()}` : undefined);
</script>

{#snippet before()}
<NeoColorPickerSelector
bind:ref={pickerRef}
bind:value
aria-labelledby={labelId}
height="100%"
rounded={rest.rounded}
disabled={rest.disabled}
Expand Down Expand Up @@ -122,4 +127,5 @@
{minlength}
{maxlength}
{...rest}
labelProps={{ id: labelId, ...rest.labelProps }}
/>
10 changes: 8 additions & 2 deletions src/lib/inputs/NeoPin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
}: NeoPinProps = $props();
/* eslint-enable prefer-const */
const labelId = $derived(label ? `neo-pin-label-${getUUID()}` : undefined);
const refs = $state<NeoInputHTMLElement[][]>(Array(Number(groups)).fill([]));
const values = $state<string[][]>(Array(Number(groups)).fill(Array(Number(count)).fill('')));
const touches = $state<boolean[][]>(Array(Number(groups)).fill(Array(Number(count)).fill(false)));
Expand Down Expand Up @@ -393,14 +395,17 @@
bind:value
oninvalid={onInvalid}
/>
{#each Array(Number(groups)) as _, i}
{#each { length: Number(groups) } as _, i}
<div class="neo-pin-group">
{#each Array(Number(count)) as __, j}
{#each { length: Number(count) } as __, j}
<NeoInput
bind:ref={refs[i][j]}
bind:value={values[i][j]}
bind:dirty={dirtiness[i][j]}
bind:touched={touches[i][j]}
data-group={i + 1}
data-count={j + 1}
aria-labelledby={labelId}
size={1}
maxlength={1}
minlength={1}
Expand Down Expand Up @@ -485,6 +490,7 @@
{#if label}
<NeoLabel
for={id}
id={labelId}
bind:ref={labelRef}
{required}
label={labelGroup}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/inputs/NeoRadio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
}: NeoRadioProps = $props();
/* eslint-enable prefer-const */
const labelId = $derived(label ? `neo-radio-label-${getUUID()}` : undefined);
const elevation = $derived(coerce(rest?.elevation ?? DefaultShadowShallowElevation));
let initial = $state(checked);
Expand Down Expand Up @@ -108,6 +109,7 @@
class={['neo-radio-input', rest.class]}
/>
<NeoRadioButton
aria-labelledby={labelId}
{checked}
{touched}
{rounded}
Expand All @@ -121,7 +123,7 @@
onclick={() => ref?.click()}
{...buttonProps}
/>
<NeoLabel bind:ref={labelRef} for={id} {label} {disabled} {required} {...labelProps} />
<NeoLabel bind:ref={labelRef} id={labelId} for={id} {label} {disabled} {required} {...labelProps} />
{#if loading !== undefined}
<span class="neo-radio-suffix">
{#if loading}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/inputs/NeoRange.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
bind:this={lowerTooltip.elements.reference}
class="neo-range-handle"
style:--neo-range-handler-z-index={lastIndex ? 0 : 1}
aria-label="Drag to set {isArray ? 'lower ' : ''}value"
{...handler}
>
<!-- handle handle -->
Expand All @@ -449,7 +450,7 @@
<span class="neo-range-handle-before neo-range">
<!-- handle before -->
</span>
<button bind:this={upperTooltip.elements.reference} class="neo-range-handle" {...progressHandler}>
<button bind:this={upperTooltip.elements.reference} class="neo-range-handle" aria-label="Drag to set upper value" {...progressHandler}>
<!-- handle handle -->
</button>
{/if}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/inputs/NeoSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
}
};
// TODO - rework container/wrapper tags
// TODO - rework focus highlights
// TODO - button rework css top match elevation / pressed (in place of hover)
</script>
Expand Down Expand Up @@ -171,7 +172,7 @@
bind:focused
bind:focusin
bind:value
display={(display ?? customDisplay) ? (customDisplay ?? display?.(value)) : undefined}
display={(display ?? customDisplay) ? (customDisplay ?? display?.(selected)) : undefined}
{rounded}
{floating}
{clearable}
Expand All @@ -193,9 +194,9 @@
...affixProps,
closeProps: { onclick: onClear, ...affixProps?.closeProps },
}}
containerTag="button"
containerProps={{
role: 'select',
tabindex: 0,
role: null,
onclick: toggle,
onkeydown,
...rest.containerProps,
Expand Down
4 changes: 3 additions & 1 deletion src/lib/inputs/NeoSwitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
}: NeoSwitchProps = $props();
/* eslint-enable prefer-const */
const labelId = $derived(label ? `neo-switch-label-${getUUID()}` : undefined);
const elevation = $derived(coerce(rest?.elevation ?? DefaultShadowShallowElevation));
let initial = $state(checked);
Expand Down Expand Up @@ -172,6 +173,7 @@
class={['neo-switch-input', rest.class]}
/>
<NeoSwitchButton
aria-labelledby={labelId}
{handle}
{off}
{on}
Expand All @@ -189,7 +191,7 @@
onclick={() => ref?.click()}
{...buttonProps}
/>
<NeoLabel bind:ref={labelRef} for={id} {label} {disabled} {required} {...labelProps} />
<NeoLabel bind:ref={labelRef} id={labelId} for={id} {label} {disabled} {required} {...labelProps} />
{#if loading !== undefined}
<span class="neo-switch-suffix">
{#if loading}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/inputs/NeoTextarea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,11 @@
/**
* Change the value of the input
*/
export const change: NeoInputMethods<HTMLTextAreaElement>['change'] = (_value: NeoInputValue<HTMLTextAreaElement>, event?: InputEvent) => {
if (event) ref?.dispatchEvent(event);
export const change: NeoInputMethods<HTMLTextAreaElement>['change'] = async (_value: NeoInputValue<HTMLTextAreaElement>, event?: InputEvent) => {
value = _value;
focus();
await tick();
if (event) ref?.dispatchEvent(event);
return validate();
};
Expand Down
4 changes: 2 additions & 2 deletions src/lib/inputs/common/NeoBaseInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@
/**
* Change the state of the input
*/
export const change: NeoInputMethods<HTMLInputElement>['change'] = (_value: NeoInputValue<HTMLInputElement>, event?: InputEvent) => {
export const change: NeoInputMethods<HTMLInputElement>['change'] = async (_value: NeoInputValue<HTMLInputElement>, event?: InputEvent) => {
if (rest.type === 'checkbox' || rest.type === 'radio') {
checked = !!_value;
} else {
value = _value?.toString();
}
focus();
await tick();
if (event) ref?.dispatchEvent(event);
return validate();
};
Expand Down Expand Up @@ -253,7 +254,6 @@
/>
<svelte:element
this={displayTag}
{id}
class:neo-input={true}
class:neo-after={after}
class:neo-before={before}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/inputs/common/NeoInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,11 @@
.neo-input-before,
.neo-input-after {
display: inline-flex;
align-items: center;
box-sizing: border-box;
min-width: min-content;
font: inherit;
text-align: start;
text-decoration: none;
outline: none;
transition:
Expand All @@ -468,6 +470,7 @@
border-color 0.3s ease,
border-radius 0.3s ease,
box-shadow 0.3s ease-out;
appearance: none;
}
.neo-input {
Expand Down
Loading

0 comments on commit 5c73810

Please sign in to comment.