@stacksjs/components 0.2.370 → 0.2.372

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.
@@ -3,6 +3,17 @@ export const headingText = $props.headingText || 'Sign up for Stacks'
3
3
  export const showSocialSignup = $bool($props.showSocialSignup, true)
4
4
  export const className = $props.className || ''
5
5
 
6
+ /*
7
+ * Field ids unique to this instance.
8
+ *
9
+ * They were `email`, `password` and the like -- names generic enough to
10
+ * collide with the host app's own ids, which breaks getElementById and
11
+ * `<label for>` for both. `name` deliberately stays generic: it is the key the
12
+ * form submits under, and it is what `autocomplete` and password managers read
13
+ * alongside `type`, so the autofill behaviour is unchanged.
14
+ */
15
+ export const fieldPrefix = $props.id || `signup-${$uid}`
16
+
6
17
  export const containerClasses = `min-h-full flex flex-col justify-center py-12 lg:px-8 sm:px-6 bg-page ${className}`.trim()
7
18
  </script>
8
19
 
@@ -33,8 +44,8 @@ function onSubmit(event) {
33
44
  emit('submit', { name, email, password })
34
45
 
35
46
  setTimeout(() => {
36
- event.target.querySelector('#password')?.setAttribute('value', '')
37
- event.target.querySelector('#confirm_email')?.setAttribute('value', '')
47
+ event.target.querySelector('input[name="password"]')?.setAttribute('value', '')
48
+ event.target.querySelector('input[name="confirm_email"]')?.setAttribute('value', '')
38
49
  }, 1000)
39
50
  }
40
51
  </script>
@@ -50,12 +61,12 @@ function onSubmit(event) {
50
61
  <div class="bg-panel px-6 py-12 shadow sm:rounded-panel sm:px-12">
51
62
  <form class="space-y-6" @submit="onSubmit($event)">
52
63
  <div>
53
- <label for="name" class="block text-sm text-fg font-medium leading-6">
64
+ <label for="{{ fieldPrefix }}-name" class="block text-sm text-fg font-medium leading-6">
54
65
  Full Name
55
66
  </label>
56
67
  <div class="mt-2">
57
68
  <input
58
- id="name"
69
+ id="{{ fieldPrefix }}-name"
59
70
  name="name"
60
71
  type="text"
61
72
  autocomplete="name"
@@ -66,12 +77,12 @@ function onSubmit(event) {
66
77
  </div>
67
78
 
68
79
  <div>
69
- <label for="email" class="block text-sm text-fg font-medium leading-6">
80
+ <label for="{{ fieldPrefix }}-email" class="block text-sm text-fg font-medium leading-6">
70
81
  Email address
71
82
  </label>
72
83
  <div class="mt-2">
73
84
  <input
74
- id="email"
85
+ id="{{ fieldPrefix }}-email"
75
86
  name="email"
76
87
  type="email"
77
88
  autocomplete="email"
@@ -82,12 +93,12 @@ function onSubmit(event) {
82
93
  </div>
83
94
 
84
95
  <div>
85
- <label for="confirm_email" class="block text-sm text-fg font-medium leading-6">
96
+ <label for="{{ fieldPrefix }}-confirm_email" class="block text-sm text-fg font-medium leading-6">
86
97
  Confirm Email
87
98
  </label>
88
99
  <div class="mt-2">
89
100
  <input
90
- id="confirm_email"
101
+ id="{{ fieldPrefix }}-confirm_email"
91
102
  name="confirm_email"
92
103
  type="email"
93
104
  autocomplete="email"
@@ -98,12 +109,12 @@ function onSubmit(event) {
98
109
  </div>
99
110
 
100
111
  <div>
101
- <label for="password" class="block text-sm text-fg font-medium leading-6">
112
+ <label for="{{ fieldPrefix }}-password" class="block text-sm text-fg font-medium leading-6">
102
113
  Password
103
114
  </label>
104
115
  <div class="mt-2">
105
116
  <input
106
- id="password"
117
+ id="{{ fieldPrefix }}-password"
107
118
  name="password"
108
119
  type="password"
109
120
  autocomplete="new-password"
@@ -6,12 +6,32 @@ export const codeLength = $props.codeLength || 6
6
6
  export const showRecoveryCode = $bool($props.showRecoveryCode, true)
7
7
  export const className = $props.className || ''
8
8
 
9
+ /*
10
+ * The digit inputs' ids, unique to this instance.
11
+ *
12
+ * They were `code-0` ... `code-5`, and the focus management looks them up with
13
+ * `document.getElementById` -- a DOCUMENT-wide lookup on an id as generic as
14
+ * `code-1`. Any element in the host app with that id would take the focus
15
+ * instead, and two of these on a page would type into each other.
16
+ *
17
+ * `name` deliberately stays `code-<i>`: that is the key the form submits
18
+ * under, so namespacing it would change the payload a server sees. Only the
19
+ * id, which exists to connect the label and the focus moves, is instance-local.
20
+ */
21
+ export const codeIdPrefix = $props.id || `code-${$uid}`
22
+
9
23
  export const containerClasses = `py-32 bg-page ${className}`.trim()
10
24
  </script>
11
25
 
12
26
  <script client>
13
27
  const emit = defineEmits()
14
28
  const codeLength = {{ codeLength }}
29
+ const codeIdPrefix = {{ codeIdPrefix }}
30
+
31
+ /** The digit input at `index`, found by this instance's own id. */
32
+ function codeInput(index) {
33
+ return document.getElementById(codeIdPrefix + '-' + index)
34
+ }
15
35
 
16
36
  function onCodeInput(event, index) {
17
37
  const input = event.target
@@ -21,13 +41,13 @@ function onCodeInput(event, index) {
21
41
  return
22
42
  }
23
43
  if (value.length === 1 && index < codeLength - 1) {
24
- document.getElementById(`code-${index + 1}`)?.focus()
44
+ codeInput(index + 1)?.focus()
25
45
  }
26
46
  }
27
47
 
28
48
  function onKeyDown(event, index) {
29
49
  if (event.key === 'Backspace' && !event.target.value && index > 0) {
30
- document.getElementById(`code-${index - 1}`)?.focus()
50
+ codeInput(index - 1)?.focus()
31
51
  }
32
52
  }
33
53
 
@@ -35,7 +55,7 @@ function onSubmit(event) {
35
55
  event.preventDefault()
36
56
  const code = []
37
57
  for (let i = 0; i < codeLength; i++) {
38
- const input = document.getElementById(`code-${i}`)
58
+ const input = codeInput(i)
39
59
  if (input?.value) code.push(input.value)
40
60
  }
41
61
  if (code.length === codeLength) {
@@ -59,14 +79,14 @@ function onRecoveryCode(event) {
59
79
  <h3 class="text-center text-sm text-fg font-semibold">
60
80
  {{ headingText }}
61
81
  </h3>
62
- <label for="code-0" class="mt-4 block text-sm text-fg font-medium leading-6">
82
+ <label for="{{ codeIdPrefix }}-0" class="mt-4 block text-sm text-fg font-medium leading-6">
63
83
  {{ labelText }}
64
84
  </label>
65
85
  <form @submit="onSubmit($event)">
66
86
  <div class="mt-2 flex rounded-control shadow-sm space-x-2">
67
87
  @for(let i = 0; i < codeLength; i++)
68
88
  <input
69
- id="code-{{ i }}"
89
+ id="{{ codeIdPrefix }}-{{ i }}"
70
90
  type="text"
71
91
  maxlength="1"
72
92
  name="code-{{ i }}"
@@ -19,7 +19,23 @@ const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-poi
19
19
  export const checkboxClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses}`.trim()
20
20
  export const labelClasses = `text-sm font-medium ${error ? 'text-danger' : 'text-fg'} ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`.trim()
21
21
  export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
22
- export const inputId = `checkbox-${value || label}`
22
+ /*
23
+ * Ids unique to this instance.
24
+ *
25
+ * These were derived from the LABEL or hardcoded outright, so two of these on
26
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
27
+ * then activated the FIRST field from every label, and `aria-describedby`
28
+ * pointed every field's description at the first one's helper text. A label
29
+ * containing a space also produced an invalid id, `input-First name`, which
30
+ * getElementById and querySelector cannot address at all.
31
+ *
32
+ * `$uid` is unique per instance and stable across renders, which is what an id
33
+ * has to be (utils.ts explains why a render that changes its own bytes is
34
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
35
+ * its own `for` or `aria-describedby` at this control.
36
+ */
37
+ export const inputId = $props.id || `checkbox-${$uid}`
38
+ export const descriptionId = `${inputId}-description`
23
39
  </script>
24
40
 
25
41
  <script client>
@@ -62,7 +78,7 @@ defineExpose({ isChecked })
62
78
  class="{{ checkboxClasses }}"
63
79
  @change="onInputChange($event)"
64
80
  :aria-invalid="{{ error ? 'true' : 'false' }}"
65
- @if(description)aria-describedby="checkbox-description"@endif
81
+ @if(description)aria-describedby="{{ descriptionId }}"@endif
66
82
  />
67
83
  </div>
68
84
 
@@ -77,7 +93,7 @@ defineExpose({ isChecked })
77
93
  </label>
78
94
  @endif
79
95
  @if(description)
80
- <p id="checkbox-description" class="{{ descriptionClasses }}">
96
+ <p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
81
97
  {{ description }}
82
98
  </p>
83
99
  @endif
@@ -6,6 +6,23 @@ export const readonly = $bool($props.readonly)
6
6
  export const size = $props.size || 'md'
7
7
  export const error = $bool($props.error)
8
8
  export const label = $props.label || ''
9
+ /*
10
+ * Ids unique to this instance.
11
+ *
12
+ * These were derived from the LABEL or hardcoded outright, so two of these on
13
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
14
+ * then activated the FIRST field from every label, and `aria-describedby`
15
+ * pointed every field's description at the first one's helper text. A label
16
+ * containing a space also produced an invalid id, `input-First name`, which
17
+ * getElementById and querySelector cannot address at all.
18
+ *
19
+ * `$uid` is unique per instance and stable across renders, which is what an id
20
+ * has to be (utils.ts explains why a render that changes its own bytes is
21
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
22
+ * its own `for` or `aria-describedby` at this control.
23
+ */
24
+ export const inputId = $props.id || `number-input-${$uid}`
25
+ export const helperId = `${inputId}-helper`
9
26
  export const helperText = $props.helperText || ''
10
27
  export const required = $bool($props.required)
11
28
  export const min = $props.min
@@ -76,7 +93,7 @@ defineExpose({ value: inputValue, increment, decrement })
76
93
 
77
94
  <div class="w-full {{ className }}">
78
95
  @if(label)
79
- <label for="number-input" class="{{ labelClasses }}">
96
+ <label for="{{ inputId }}" class="{{ labelClasses }}">
80
97
  {{ label }}
81
98
  @if(required)
82
99
  <span class="text-danger ml-1">*</span>
@@ -87,7 +104,7 @@ defineExpose({ value: inputValue, increment, decrement })
87
104
  <div class="relative">
88
105
  <input
89
106
  type="number"
90
- id="number-input"
107
+ id="{{ inputId }}"
91
108
  class="{{ inputClasses }}"
92
109
  :value="inputValue()"
93
110
  placeholder="{{ placeholder }}"
@@ -99,7 +116,7 @@ defineExpose({ value: inputValue, increment, decrement })
99
116
  step="{{ step }}"
100
117
  @input="onInput($event)"
101
118
  :aria-invalid="{{ error ? 'true' : 'false' }}"
102
- @if(helperText)aria-describedby="helper-text"@endif
119
+ @if(helperText)aria-describedby="{{ helperId }}"@endif
103
120
  />
104
121
 
105
122
  @if(showControls && !disabled && !readonly)
@@ -129,7 +146,7 @@ defineExpose({ value: inputValue, increment, decrement })
129
146
  </div>
130
147
 
131
148
  @if(helperText)
132
- <p id="helper-text" class="{{ helperClasses }}">
149
+ <p id="{{ helperId }}" class="{{ helperClasses }}">
133
150
  {{ helperText }}
134
151
  </p>
135
152
  @endif
@@ -6,6 +6,23 @@ export const readonly = $bool($props.readonly)
6
6
  export const size = $props.size || 'md'
7
7
  export const error = $bool($props.error)
8
8
  export const label = $props.label || ''
9
+ /*
10
+ * Ids unique to this instance.
11
+ *
12
+ * These were derived from the LABEL or hardcoded outright, so two of these on
13
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
14
+ * then activated the FIRST field from every label, and `aria-describedby`
15
+ * pointed every field's description at the first one's helper text. A label
16
+ * containing a space also produced an invalid id, `input-First name`, which
17
+ * getElementById and querySelector cannot address at all.
18
+ *
19
+ * `$uid` is unique per instance and stable across renders, which is what an id
20
+ * has to be (utils.ts explains why a render that changes its own bytes is
21
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
22
+ * its own `for` or `aria-describedby` at this control.
23
+ */
24
+ export const inputId = $props.id || `password-input-${$uid}`
25
+ export const helperId = `${inputId}-helper`
9
26
  export const helperText = $props.helperText || ''
10
27
  export const required = $bool($props.required)
11
28
  export const showStrength = $bool($props.showStrength)
@@ -88,7 +105,7 @@ defineExpose({ value: inputValue })
88
105
 
89
106
  <div class="w-full {{ className }}">
90
107
  @if(label)
91
- <label for="password-input" class="{{ labelClasses }}">
108
+ <label for="{{ inputId }}" class="{{ labelClasses }}">
92
109
  {{ label }}
93
110
  @if(required)
94
111
  <span class="text-danger ml-1">*</span>
@@ -99,7 +116,7 @@ defineExpose({ value: inputValue })
99
116
  <div class="relative">
100
117
  <input
101
118
  :type="inputType()"
102
- id="password-input"
119
+ id="{{ inputId }}"
103
120
  class="{{ inputClasses }}"
104
121
  :value="inputValue()"
105
122
  placeholder="{{ placeholder }}"
@@ -108,7 +125,7 @@ defineExpose({ value: inputValue })
108
125
  @if(required)required@endif
109
126
  @input="onInput($event)"
110
127
  :aria-invalid="{{ error ? 'true' : 'false' }}"
111
- @if(helperText)aria-describedby="helper-text"@endif
128
+ @if(helperText)aria-describedby="{{ helperId }}"@endif
112
129
  />
113
130
 
114
131
  <div class="absolute inset-y-0 right-0 flex items-center pr-3">
@@ -146,7 +163,7 @@ defineExpose({ value: inputValue })
146
163
  @endif
147
164
 
148
165
  @if(helperText)
149
- <p id="helper-text" class="{{ helperClasses }}">
166
+ <p id="{{ helperId }}" class="{{ helperClasses }}">
150
167
  {{ helperText }}
151
168
  </p>
152
169
  @endif
@@ -44,7 +44,23 @@ export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.m
44
44
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
45
45
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
46
46
  export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
47
- export const inputId = `input-${label}`
47
+ /*
48
+ * Ids unique to this instance.
49
+ *
50
+ * These were derived from the LABEL or hardcoded outright, so two of these on
51
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
52
+ * then activated the FIRST field from every label, and `aria-describedby`
53
+ * pointed every field's description at the first one's helper text. A label
54
+ * containing a space also produced an invalid id, `input-First name`, which
55
+ * getElementById and querySelector cannot address at all.
56
+ *
57
+ * `$uid` is unique per instance and stable across renders, which is what an id
58
+ * has to be (utils.ts explains why a render that changes its own bytes is
59
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
60
+ * its own `for` or `aria-describedby` at this control.
61
+ */
62
+ export const inputId = $props.id || `input-${$uid}`
63
+ export const helperId = `${inputId}-helper`
48
64
  </script>
49
65
 
50
66
  <script client>
@@ -104,7 +120,7 @@ defineExpose({ value: inputValue, clear: onClear })
104
120
  @input="onInput($event)"
105
121
  @change="onChange($event)"
106
122
  :aria-invalid="{{ error ? 'true' : 'false' }}"
107
- @if(helperText)aria-describedby="helper-text"@endif
123
+ @if(helperText)aria-describedby="{{ helperId }}"@endif
108
124
  />
109
125
 
110
126
  @if(clearable)
@@ -131,7 +147,7 @@ defineExpose({ value: inputValue, clear: onClear })
131
147
  @if(helperText || (showCount && maxLength))
132
148
  <div class="flex items-center justify-between mt-2">
133
149
  @if(helperText)
134
- <p id="helper-text" class="{{ helperClasses }}">
150
+ <p id="{{ helperId }}" class="{{ helperClasses }}">
135
151
  {{ helperText }}
136
152
  </p>
137
153
  @else
@@ -10,10 +10,26 @@ export const className = $props.className || ''
10
10
  export const subtotal = products.reduce((sum, product) => sum + (product.price * (product.quantity || 1)), 0)
11
11
  export const total = subtotal + shipping + taxes
12
12
 
13
+ /*
14
+ * Field ids unique to this instance.
15
+ *
16
+ * `email-address`, `card-name`, `credit-card` and `payment-element` were
17
+ * generic enough to collide with the host app's own ids, which breaks
18
+ * getElementById and `<label for>` for both. `name` stays generic: it is the
19
+ * key the form submits under and what autocomplete reads.
20
+ *
21
+ * `payment-element` matters most of the three, because it is not only a label
22
+ * target -- Stripe mounts into it BY SELECTOR (`#payment-element` below), so a
23
+ * second element with that id anywhere on the page could take the card form.
24
+ * Both sides read the same prefix, so they cannot drift apart.
25
+ */
26
+ export const fieldPrefix = $props.id || `checkout-${$uid}`
27
+
13
28
  export const containerClasses = `bg-page ${className}`.trim()
14
29
  </script>
15
30
 
16
31
  <script client>
32
+ const fieldPrefix = {{ fieldPrefix }}
17
33
  const emit = defineEmits()
18
34
  const stripePublicKey = {{ stripePublicKey }}
19
35
  const apiUrl = {{ apiUrl }}
@@ -52,7 +68,7 @@ async function setupStripeElements() {
52
68
  },
53
69
  })
54
70
  paymentElement = elements.create('payment')
55
- paymentElement.mount('#payment-element')
71
+ paymentElement.mount('#' + fieldPrefix + '-payment-element')
56
72
  }
57
73
  catch (error) {
58
74
  console.error('Error setting up Stripe elements:', error)
@@ -120,12 +136,12 @@ onMount(() => initializeStripe())
120
136
  </h2>
121
137
 
122
138
  <div class="mt-4">
123
- <label for="email-address" class="block text-sm text-fg-strong font-medium">
139
+ <label for="{{ fieldPrefix }}-email-address" class="block text-sm text-fg-strong font-medium">
124
140
  Email address
125
141
  </label>
126
142
  <div class="mt-1">
127
143
  <input
128
- id="email-address"
144
+ id="{{ fieldPrefix }}-email-address"
129
145
  type="email"
130
146
  name="email-address"
131
147
  autocomplete="email"
@@ -144,13 +160,13 @@ onMount(() => initializeStripe())
144
160
 
145
161
  <div class="mt-4 grid grid-cols-1 gap-y-6 sm:grid-cols-2 sm:gap-x-4">
146
162
  <div class="sm:col-span-2">
147
- <label for="card-name" class="block text-sm text-fg-strong font-medium">
163
+ <label for="{{ fieldPrefix }}-card-name" class="block text-sm text-fg-strong font-medium">
148
164
  Name on card
149
165
  </label>
150
166
  <div class="mt-1">
151
167
  <input
152
168
  type="text"
153
- id="card-name"
169
+ id="{{ fieldPrefix }}-card-name"
154
170
  name="card-name"
155
171
  autocomplete="cc-name"
156
172
  required
@@ -161,7 +177,7 @@ onMount(() => initializeStripe())
161
177
 
162
178
  <!-- Stripe Element Mount Point -->
163
179
  <div class="sm:col-span-2">
164
- <div id="payment-element" class="mt-2 border border-line-strong rounded-control bg-field p-3"></div>
180
+ <div id="{{ fieldPrefix }}-payment-element" class="mt-2 border border-line-strong rounded-control bg-field p-3"></div>
165
181
  </div>
166
182
  </div>
167
183
  </div>
@@ -177,13 +193,13 @@ onMount(() => initializeStripe())
177
193
  <div class="sm:flex sm:items-center space-y-4 sm:space-x-10 sm:space-y-0">
178
194
  <div class="flex items-center">
179
195
  <input
180
- id="credit-card"
196
+ id="{{ fieldPrefix }}-credit-card"
181
197
  name="payment-type"
182
198
  type="radio"
183
199
  checked
184
200
  class="h-4 w-4 border-line-strong text-accent focus:ring-accent"
185
201
  />
186
- <label for="credit-card" class="ml-3 block text-sm text-fg-strong font-medium">
202
+ <label for="{{ fieldPrefix }}-credit-card" class="ml-3 block text-sm text-fg-strong font-medium">
187
203
  Credit card
188
204
  </label>
189
205
  </div>
@@ -256,9 +272,9 @@ onMount(() => initializeStripe())
256
272
  </p>
257
273
 
258
274
  <div class="ml-4">
259
- <label for="quantity-{{ product.id }}" class="sr-only">Quantity</label>
275
+ <label for="{{ fieldPrefix }}-quantity-{{ product.id }}" class="sr-only">Quantity</label>
260
276
  <select
261
- id="quantity-{{ product.id }}"
277
+ id="{{ fieldPrefix }}-quantity-{{ product.id }}"
262
278
  name="quantity"
263
279
  class="border border-line-strong rounded-control text-left text-base text-fg-strong font-medium shadow-sm bg-field focus:border-accent sm:text-sm focus:outline-none focus:ring-1 focus:ring-accent"
264
280
  >
@@ -18,7 +18,23 @@ const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-poi
18
18
  export const radioClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses}`.trim()
19
19
  export const labelClasses = `text-sm font-medium ${error ? 'text-danger' : 'text-fg'} ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`.trim()
20
20
  export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
21
- export const inputId = `radio-${value || label}`
21
+ /*
22
+ * Ids unique to this instance.
23
+ *
24
+ * These were derived from the LABEL or hardcoded outright, so two of these on
25
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
26
+ * then activated the FIRST field from every label, and `aria-describedby`
27
+ * pointed every field's description at the first one's helper text. A label
28
+ * containing a space also produced an invalid id, `input-First name`, which
29
+ * getElementById and querySelector cannot address at all.
30
+ *
31
+ * `$uid` is unique per instance and stable across renders, which is what an id
32
+ * has to be (utils.ts explains why a render that changes its own bytes is
33
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
34
+ * its own `for` or `aria-describedby` at this control.
35
+ */
36
+ export const inputId = $props.id || `radio-${$uid}`
37
+ export const descriptionId = `${inputId}-description`
22
38
  </script>
23
39
 
24
40
  <script client>
@@ -53,7 +69,7 @@ defineExpose({ isChecked })
53
69
  class="{{ radioClasses }}"
54
70
  @change="onInputChange($event)"
55
71
  :aria-invalid="{{ error ? 'true' : 'false' }}"
56
- @if(description)aria-describedby="radio-description"@endif
72
+ @if(description)aria-describedby="{{ descriptionId }}"@endif
57
73
  />
58
74
  </div>
59
75
 
@@ -68,7 +84,7 @@ defineExpose({ isChecked })
68
84
  </label>
69
85
  @endif
70
86
  @if(description)
71
- <p id="radio-description" class="{{ descriptionClasses }}">
87
+ <p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
72
88
  {{ description }}
73
89
  </p>
74
90
  @endif
@@ -32,7 +32,23 @@ const disabledClasses = disabled
32
32
  export const selectClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses} ${className}`.trim()
33
33
  export const labelClasses = `block text-sm font-medium leading-6 ${error ? 'text-danger' : 'text-fg'}`.trim()
34
34
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
35
- export const selectId = `select-${value}`
35
+ /*
36
+ * Ids unique to this instance.
37
+ *
38
+ * These were derived from the LABEL or hardcoded outright, so two of these on
39
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
40
+ * then activated the FIRST field from every label, and `aria-describedby`
41
+ * pointed every field's description at the first one's helper text. A label
42
+ * containing a space also produced an invalid id, `input-First name`, which
43
+ * getElementById and querySelector cannot address at all.
44
+ *
45
+ * `$uid` is unique per instance and stable across renders, which is what an id
46
+ * has to be (utils.ts explains why a render that changes its own bytes is
47
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
48
+ * its own `for` or `aria-describedby` at this control.
49
+ */
50
+ export const selectId = $props.id || `select-${$uid}`
51
+ export const helperId = `${selectId}-helper`
36
52
  </script>
37
53
 
38
54
  <script client>
@@ -67,7 +83,7 @@ defineExpose({ value: selectedValue })
67
83
  @if(required)required@endif
68
84
  @change="onChange($event)"
69
85
  :aria-invalid="{{ error ? 'true' : 'false' }}"
70
- aria-describedby="{{ helperText ? 'helper-text' : '' }}"
86
+ aria-describedby="{{ helperText ? helperId : '' }}"
71
87
  >
72
88
  @if(placeholder)
73
89
  <option value="" disabled>{{ placeholder }}</option>
@@ -85,7 +101,7 @@ defineExpose({ value: selectedValue })
85
101
  </div>
86
102
 
87
103
  @if(helperText)
88
- <p id="helper-text" class="{{ helperClasses }}">
104
+ <p id="{{ helperId }}" class="{{ helperClasses }}">
89
105
  {{ helperText }}
90
106
  </p>
91
107
  @endif
@@ -8,6 +8,23 @@ export const autoResize = $bool($props.autoResize)
8
8
  export const maxRows = $props.maxRows || 10
9
9
  export const error = $bool($props.error)
10
10
  export const label = $props.label || ''
11
+ /*
12
+ * Ids unique to this instance.
13
+ *
14
+ * These were derived from the LABEL or hardcoded outright, so two of these on
15
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
16
+ * then activated the FIRST field from every label, and `aria-describedby`
17
+ * pointed every field's description at the first one's helper text. A label
18
+ * containing a space also produced an invalid id, `input-First name`, which
19
+ * getElementById and querySelector cannot address at all.
20
+ *
21
+ * `$uid` is unique per instance and stable across renders, which is what an id
22
+ * has to be (utils.ts explains why a render that changes its own bytes is
23
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
24
+ * its own `for` or `aria-describedby` at this control.
25
+ */
26
+ export const inputId = $props.id || `textarea-input-${$uid}`
27
+ export const helperId = `${inputId}-helper`
11
28
  export const helperText = $props.helperText || ''
12
29
  export const required = $bool($props.required)
13
30
  export const maxLength = $props.maxLength
@@ -68,7 +85,7 @@ defineExpose({ value: inputValue })
68
85
 
69
86
  <div class="w-full">
70
87
  @if(label)
71
- <label for="textarea-input" class="{{ labelClasses }}">
88
+ <label for="{{ inputId }}" class="{{ labelClasses }}">
72
89
  {{ label }}
73
90
  @if(required)
74
91
  <span class="text-danger ml-1">*</span>
@@ -77,7 +94,7 @@ defineExpose({ value: inputValue })
77
94
  @endif
78
95
 
79
96
  <textarea
80
- id="textarea-input"
97
+ id="{{ inputId }}"
81
98
  class="{{ textareaClasses }}"
82
99
  rows="{{ rows }}"
83
100
  placeholder="{{ placeholder }}"
@@ -87,13 +104,13 @@ defineExpose({ value: inputValue })
87
104
  @if(maxLength)maxlength="{{ maxLength }}"@endif
88
105
  @input="onInput($event)"
89
106
  :aria-invalid="{{ error ? 'true' : 'false' }}"
90
- @if(helperText)aria-describedby="helper-text"@endif
107
+ @if(helperText)aria-describedby="{{ helperId }}"@endif
91
108
  >{{ value }}</textarea>
92
109
 
93
110
  @if(helperText || (showCount && maxLength))
94
111
  <div class="flex items-center justify-between mt-2">
95
112
  @if(helperText)
96
- <p id="helper-text" class="{{ helperClasses }}">
113
+ <p id="{{ helperId }}" class="{{ helperClasses }}">
97
114
  {{ helperText }}
98
115
  </p>
99
116
  @else