@duro-app/ui 5.34.3 → 5.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duro-app/ui",
3
- "version": "5.34.3",
3
+ "version": "5.35.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -92,7 +92,7 @@
92
92
  "dependencies": {
93
93
  "@tanstack/react-virtual": "^3.14.13",
94
94
  "qrcode": "^1.5.4",
95
- "@duro-app/tokens": "^5.34.3"
95
+ "@duro-app/tokens": "^5.35.0"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@babel/preset-typescript": "^7.28.0",
@@ -17,6 +17,7 @@ export function Switch({
17
17
  onCheckedChange,
18
18
  disabled = false,
19
19
  children,
20
+ 'aria-label': ariaLabel,
20
21
  }: SwitchProps) {
21
22
  const [checked, setChecked] = useControllableValue(
22
23
  controlledChecked,
@@ -33,6 +34,7 @@ export function Switch({
33
34
  type="button"
34
35
  role="switch"
35
36
  aria-checked={checked}
37
+ aria-label={!children ? ariaLabel : undefined}
36
38
  disabled={disabled}
37
39
  onClick={handleClick}
38
40
  style={[styles.track, checked ? styles.trackChecked : styles.trackUnchecked]}
@@ -40,6 +40,16 @@ export const Checked: Story = {
40
40
  },
41
41
  }
42
42
 
43
+ /** No visible label: a settings row shows the title, and `aria-label` names the switch. */
44
+ export const Labelled: Story = {
45
+ args: {'aria-label': 'Analytics'},
46
+ play: async ({canvas, userEvent, args}) => {
47
+ const switchEl = canvas.getByRole('switch', {name: 'Analytics'})
48
+ await userEvent.click(switchEl)
49
+ await expect(args.onCheckedChange).toHaveBeenCalledWith(true)
50
+ },
51
+ }
52
+
43
53
  export const Disabled: Story = {
44
54
  args: {disabled: true, children: 'Cannot toggle'},
45
55
  play: async ({canvas, userEvent, args}) => {
@@ -15,6 +15,7 @@ export function Switch({
15
15
  name,
16
16
  value,
17
17
  children,
18
+ 'aria-label': ariaLabel,
18
19
  }: SwitchProps) {
19
20
  const [checked, setChecked] = useControllableValue(
20
21
  controlledChecked,
@@ -46,6 +47,7 @@ export function Switch({
46
47
  defaultChecked={controlledChecked === undefined ? defaultChecked : undefined}
47
48
  disabled={disabled}
48
49
  aria-checked={checked}
50
+ aria-label={!children ? ariaLabel : undefined}
49
51
  onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
50
52
  onCheckedChange?.(e.target.checked)
51
53
  }}
@@ -15,4 +15,6 @@ export interface SwitchProps {
15
15
  value?: string
16
16
  /** Label content rendered beside the switch. */
17
17
  children?: ReactNode
18
+ /** Names the switch when it has no visible label (`children`), e.g. a row whose title already shows it. */
19
+ 'aria-label'?: string
18
20
  }