@classic-homes/theme-svelte 1.2.0 → 1.2.1

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.
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
2
2
  import { render, screen } from '@testing-library/svelte';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { axe } from 'vitest-axe';
5
+ import { createRawSnippet } from 'svelte';
5
6
  import Tabs from '../../lib/components/Tabs.svelte';
6
7
  describe('Tabs accessibility', () => {
7
8
  const defaultTabs = [
@@ -85,13 +86,31 @@ describe('Tabs accessibility', () => {
85
86
  await user.click(tabs[1]);
86
87
  expect(tabs[1]).toHaveAttribute('aria-selected', 'true');
87
88
  });
88
- it('should have aria-controls linking tab to panel', () => {
89
+ it('should omit aria-controls when no panel exists', () => {
90
+ // Without children there is no panel in the DOM; an aria-controls pointing
91
+ // at a missing element is an ARIA validity failure (axe: aria-valid-attr-value)
89
92
  render(Tabs, {
90
93
  props: { tabs: defaultTabs, label: 'Test tabs' },
91
94
  });
95
+ for (const tab of screen.getAllByRole('tab')) {
96
+ expect(tab).not.toHaveAttribute('aria-controls');
97
+ }
98
+ });
99
+ it('should have aria-controls referencing a real panel when children exist', () => {
100
+ const children = createRawSnippet(() => ({
101
+ render: () => '<div id="test-tabs-panel-tab1" role="tabpanel">Panel 1</div>',
102
+ }));
103
+ render(Tabs, {
104
+ props: { tabs: defaultTabs, value: 'tab1', id: 'test-tabs', label: 'Test tabs', children },
105
+ });
92
106
  const tabs = screen.getAllByRole('tab');
93
- // Selected tab should have aria-controls
94
107
  const selectedTab = tabs.find((tab) => tab.getAttribute('aria-selected') === 'true');
95
- expect(selectedTab).toHaveAttribute('aria-controls');
108
+ expect(selectedTab).toHaveAttribute('aria-controls', 'test-tabs-panel-tab1');
109
+ // The reference must resolve to an element that exists
110
+ expect(document.getElementById('test-tabs-panel-tab1')).not.toBeNull();
111
+ // Unselected tabs have no panel mounted, so no aria-controls
112
+ for (const tab of tabs.filter((t) => t !== selectedTab)) {
113
+ expect(tab).not.toHaveAttribute('aria-controls');
114
+ }
96
115
  });
97
116
  });
@@ -4,7 +4,7 @@
4
4
  import { tv, type VariantProps } from 'tailwind-variants';
5
5
 
6
6
  const buttonVariants = tv({
7
- base: 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
7
+ base: 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg text-sm font-medium ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50',
8
8
  variants: {
9
9
  variant: {
10
10
  default: 'bg-primary text-primary-foreground shadow hover:bg-primary-hover',
@@ -54,7 +54,7 @@
54
54
  dark: {
55
55
  logo: '#C50F22', // Brand red
56
56
  title: '#000000', // Black for light backgrounds
57
- subtitle: '#7a7a7a', // Gray
57
+ subtitle: '#666666', // Gray - #7a7a7a was 4.29:1 on white (WCAG 1.4.3 fail)
58
58
  },
59
59
  light: {
60
60
  logo: '#ffffff',
@@ -64,7 +64,7 @@
64
64
  'mono-dark': {
65
65
  logo: '#002e3f', // Navy
66
66
  title: '#002e3f',
67
- subtitle: '#7a7a7a',
67
+ subtitle: '#666666', // see dark variant note
68
68
  },
69
69
  'mono-light': {
70
70
  logo: '#ffffff',
@@ -31,6 +31,19 @@
31
31
  ...restProps
32
32
  }: Props = $props();
33
33
 
34
+ // Dev-mode a11y warning, matching Input/Select/Button: a Switch with no
35
+ // aria-label, aria-labelledby, or id (for an external <label for>) announces
36
+ // as a bare "switch" with no name.
37
+ if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {
38
+ $effect(() => {
39
+ if (!ariaLabel && !ariaLabelledby && !id) {
40
+ console.warn(
41
+ 'Switch: provide aria-label, aria-labelledby, or an id paired with a <label for> so the switch has an accessible name.'
42
+ );
43
+ }
44
+ });
45
+ }
46
+
34
47
  // Handle checked state changes from user interaction
35
48
  // The primitive handles the actual state management via bind:checked
36
49
  function handleCheckedChange(newChecked: boolean) {
@@ -19,7 +19,16 @@
19
19
  label: string;
20
20
  /** Additional classes for container */
21
21
  class?: string;
22
- /** Tab panel content */
22
+ /**
23
+ * Tab panel content - compose with `TabPanel` so each panel gets the
24
+ * matching `role="tabpanel"` / id / aria-labelledby wiring.
25
+ *
26
+ * aria-controls is only emitted while a panel actually exists in the DOM
27
+ * (children provided + tab active): a reference to a missing element is an
28
+ * ARIA validity failure (axe: aria-valid-attr-value). Consumers rendering
29
+ * panels OUTSIDE this component should give them
30
+ * `id="{id}-panel-{tabId}"` + `aria-labelledby="{id}-tab-{tabId}"`.
31
+ */
23
32
  children?: Snippet;
24
33
  /** Callback when active tab changes */
25
34
  onValueChange?: (value: string) => void;
@@ -111,7 +120,7 @@
111
120
  role="tab"
112
121
  type="button"
113
122
  aria-selected={value === tab.id}
114
- aria-controls={`${id}-panel-${tab.id}`}
123
+ aria-controls={children && value === tab.id ? `${id}-panel-${tab.id}` : undefined}
115
124
  tabindex={value === tab.id ? 0 : -1}
116
125
  disabled={tab.disabled}
117
126
  class={cn(
@@ -15,7 +15,16 @@ interface Props {
15
15
  label: string;
16
16
  /** Additional classes for container */
17
17
  class?: string;
18
- /** Tab panel content */
18
+ /**
19
+ * Tab panel content - compose with `TabPanel` so each panel gets the
20
+ * matching `role="tabpanel"` / id / aria-labelledby wiring.
21
+ *
22
+ * aria-controls is only emitted while a panel actually exists in the DOM
23
+ * (children provided + tab active): a reference to a missing element is an
24
+ * ARIA validity failure (axe: aria-valid-attr-value). Consumers rendering
25
+ * panels OUTSIDE this component should give them
26
+ * `id="{id}-panel-{tabId}"` + `aria-labelledby="{id}-tab-{tabId}"`.
27
+ */
19
28
  children?: Snippet;
20
29
  /** Callback when active tab changes */
21
30
  onValueChange?: (value: string) => void;
@@ -85,8 +85,8 @@
85
85
  className
86
86
  )}
87
87
  >
88
- <!-- Logo -->
89
- <div class="mb-6 flex flex-col items-center">
88
+ <!-- Logo. <header> so it isn't content outside every landmark (axe: region) -->
89
+ <header class="mb-6 flex flex-col items-center">
90
90
  {#if logo}
91
91
  {@render logo()}
92
92
  {:else}
@@ -98,7 +98,7 @@
98
98
  environment={logoEnvironment}
99
99
  />
100
100
  {/if}
101
- </div>
101
+ </header>
102
102
 
103
103
  <!-- Main Content Card -->
104
104
  <main
@@ -52,6 +52,14 @@
52
52
  footer?: Snippet;
53
53
  /** Additional classes for the container */
54
54
  class?: string;
55
+ /**
56
+ * Whether this layout owns the whole page (default). Set false when
57
+ * rendering inside an app layout that already provides the page chrome -
58
+ * e.g. a SvelteKit +error.svelte inside a layout with its own
59
+ * <main id="main-content"> - so AppShell and the main landmark aren't
60
+ * duplicated (axe: landmark-no-duplicate-main / landmark-main-is-top-level).
61
+ */
62
+ standalone?: boolean;
55
63
  /** Main content (custom error content, replaces default display) */
56
64
  children?: Snippet;
57
65
  }
@@ -72,6 +80,7 @@
72
80
  actions,
73
81
  footer,
74
82
  class: className,
83
+ standalone = true,
75
84
  children,
76
85
  }: Props = $props();
77
86
 
@@ -128,16 +137,19 @@
128
137
  }
129
138
  </script>
130
139
 
131
- <AppShell>
140
+ {#snippet layoutBody()}
132
141
  <div
133
142
  class={cn(
134
- 'flex h-screen flex-col items-center justify-center overflow-auto bg-content-bg px-4 py-8 sm:px-6 lg:px-8',
143
+ 'flex flex-col items-center justify-center overflow-auto bg-content-bg px-4 py-8 sm:px-6 lg:px-8',
144
+ standalone ? 'h-screen' : 'min-h-[60vh]',
135
145
  className
136
146
  )}
137
147
  >
138
- <!-- Logo -->
148
+ <!-- Logo. <header> so the logo isn't content outside every landmark
149
+ (axe: region); nested under a host <main> it simply loses the banner
150
+ role, which is correct. -->
139
151
  {#if showLogo}
140
- <div class="mb-6">
152
+ <header class="mb-6">
141
153
  {#if logo}
142
154
  {@render logo()}
143
155
  {:else}
@@ -145,11 +157,16 @@
145
157
  <LogoMain variant="horizontal" color="dark" size="md" />
146
158
  </a>
147
159
  {/if}
148
- </div>
160
+ </header>
149
161
  {/if}
150
162
 
151
- <!-- Main Content -->
152
- <main id="main-content" class="w-full max-w-md text-center">
163
+ <!-- Main Content. A second main landmark is invalid when the host layout
164
+ already renders one, so embedded mode uses a plain div. -->
165
+ <svelte:element
166
+ this={standalone ? 'main' : 'div'}
167
+ id={standalone ? 'main-content' : undefined}
168
+ class="w-full max-w-md text-center"
169
+ >
153
170
  {#if children}
154
171
  {@render children()}
155
172
  {:else}
@@ -197,7 +214,7 @@
197
214
  </div>
198
215
  {/if}
199
216
  {/if}
200
- </main>
217
+ </svelte:element>
201
218
 
202
219
  <!-- Footer -->
203
220
  {#if footer}
@@ -206,4 +223,12 @@
206
223
  </footer>
207
224
  {/if}
208
225
  </div>
209
- </AppShell>
226
+ {/snippet}
227
+
228
+ {#if standalone}
229
+ <AppShell>
230
+ {@render layoutBody()}
231
+ </AppShell>
232
+ {:else}
233
+ {@render layoutBody()}
234
+ {/if}
@@ -46,6 +46,14 @@ interface Props {
46
46
  footer?: Snippet;
47
47
  /** Additional classes for the container */
48
48
  class?: string;
49
+ /**
50
+ * Whether this layout owns the whole page (default). Set false when
51
+ * rendering inside an app layout that already provides the page chrome -
52
+ * e.g. a SvelteKit +error.svelte inside a layout with its own
53
+ * <main id="main-content"> - so AppShell and the main landmark aren't
54
+ * duplicated (axe: landmark-no-duplicate-main / landmark-main-is-top-level).
55
+ */
56
+ standalone?: boolean;
49
57
  /** Main content (custom error content, replaces default display) */
50
58
  children?: Snippet;
51
59
  }
@@ -65,9 +65,11 @@
65
65
  {#each links as section}
66
66
  <div>
67
67
  {#if section.title}
68
- <h3 class={cn('text-lg font-bold mb-4', isDark ? 'text-white' : 'text-foreground')}>
68
+ <!-- h2, not h3: most pages reach the footer with only an h1 in
69
+ scope, so h3 skipped a level (axe: heading-order) -->
70
+ <h2 class={cn('text-lg font-bold mb-4', isDark ? 'text-white' : 'text-foreground')}>
69
71
  {section.title}
70
- </h3>
72
+ </h2>
71
73
  {/if}
72
74
  <ul class="mt-4 space-y-2">
73
75
  {#each section.items as item}
@@ -127,7 +129,8 @@
127
129
  <LogoMain variant="horizontal" color={isDark ? 'light' : 'dark'} size="sm" />
128
130
  {/if}
129
131
 
130
- <p class={cn('text-center text-sm', isDark ? 'text-gray-400' : 'text-muted-foreground')}>
132
+ <!-- gray-300, not gray-400: #9ca3af is 3.22:1 on the gray-600 footer -->
133
+ <p class={cn('text-center text-sm', isDark ? 'text-gray-300' : 'text-muted-foreground')}>
131
134
  {displayCopyright}
132
135
  </p>
133
136
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/theme-svelte",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Svelte components for the Classic theme system",
5
5
  "type": "module",
6
6
  "svelte": "./dist/lib/index.js",