@stacksjs/components 0.2.383 → 0.2.384

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.
@@ -21,6 +21,19 @@ export const fullWidth = $bool($props.fullWidth)
21
21
  */
22
22
  export const label = $props.label || ''
23
23
  export const hasLabel = label !== ''
24
+
25
+ /*
26
+ * A server-rendered accessible name, for the one case the slot cannot cover.
27
+ *
28
+ * `:label` is client-categorised, so the server cannot see it: a
29
+ * `<Button :label="confirmLabel()" />` with no slot content has no text and no
30
+ * name in the markup actually served, and assistive technology reaching it
31
+ * before hydration finds an unlabelled button. On a destructive confirmation
32
+ * that is the worst case (stacksjs/stx#2034). Slot content is the better
33
+ * answer where there is any, because it is visible as well as announced; this
34
+ * is for a button that has neither.
35
+ */
36
+ export const ariaLabel = $props.ariaLabel || $props['aria-label'] || ''
24
37
  export const leftIcon = $props.leftIcon || ''
25
38
  export const rightIcon = $props.rightIcon || ''
26
39
  export const className = $props.className || ''
@@ -146,6 +159,7 @@ function onClick(event) {
146
159
  :disabled="isDisabled()"
147
160
  aria-busy="{{ loading ? 'true' : 'false' }}"
148
161
  :aria-busy="isLoading() ? 'true' : 'false'"
162
+ @if(ariaLabel)aria-label="{{ ariaLabel }}"@endif
149
163
  @click="onClick($event)"
150
164
  >
151
165
  {{-- The spinner is always in the DOM so `loading` can turn it on after render;
@@ -169,7 +183,24 @@ function onClick(event) {
169
183
  <span :show="!isLoading()" @if(loading)x-cloak@endif class="{{ iconClasses }}">{!! leftIcon !!}</span>
170
184
  @endif
171
185
 
172
- <slot />
186
+ {{-- The slot is the label's FALLBACK, not its sibling (stacksjs/stx#2034).
187
+
188
+ A reactive label is invisible to the server, so the only text a
189
+ `<Button :label="confirmLabel()">Confirm</Button>` can serve is the slot
190
+ content -- and it used to render it NEXT TO the label span, so once
191
+ labelText() resolved the button read "ConfirmDelete project". An author
192
+ had to choose between a server-rendered accessible name and a reactive
193
+ one, which is why the reporting app kept a plain <button>.
194
+
195
+ Wrapped rather than put on the slot itself: `<slot :if="...">` does not
196
+ work, because the slot is replaced by the caller's markup at render time
197
+ and the attribute goes with it. display:contents so the wrapper is not a
198
+ box -- slot children stay direct flex items of the button, so the gap
199
+ between them is unchanged.
200
+
201
+ `:if` rather than `:show` for the same reason: `:show` writes
202
+ style.display, which would fight the display:contents this needs. --}}
203
+ <span style="display:contents" :if="!labelText()"><slot /></span>
173
204
 
174
205
  {{-- The label span is decided on the CLIENT, because the server cannot see a
175
206
  reactive prop at all: `:label="rotateLabel()"` is categorised as client
@@ -36,6 +36,14 @@ export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-so
36
36
  */
37
37
  export const inputId = $props.id || `checkbox-${$uid}`
38
38
  export const descriptionId = `${inputId}-description`
39
+ /*
40
+ * `autocomplete` and `form`, alongside the `name` this already had
41
+ * (stacksjs/stx#2043). `autocomplete` is how the browser and a password
42
+ * manager identify a field; `form` lets a control live outside the <form>
43
+ * element it belongs to. Emitted only when given.
44
+ */
45
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
46
+ export const form = $props.form || ''
39
47
  </script>
40
48
 
41
49
  <script client>
@@ -71,6 +79,8 @@ defineExpose({ isChecked })
71
79
  id="{{ inputId }}"
72
80
  type="checkbox"
73
81
  name="{{ name }}"
82
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
83
+ @if(form)form="{{ form }}"@endif
74
84
  value="{{ value }}"
75
85
  :checked="isChecked()"
76
86
  @if(disabled)disabled@endif
@@ -11,9 +11,27 @@ export const required = $bool($props.required)
11
11
  export const className = $props.className || ''
12
12
 
13
13
  export const emailIcon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" /></svg>'
14
+ /*
15
+ * Forwarded to the TextInput this renders (stacksjs/stx#2043).
16
+ *
17
+ * A wrapper that does not pass them through is as unsubmittable as a control
18
+ * that never accepted them: the inner input is the one that lands in FormData.
19
+ * `type` is the wrapper's own business, but `name`, `autocomplete` and `form`
20
+ * belong to the caller.
21
+ */
22
+ export const name = $props.name || ''
23
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
24
+ export const form = $props.form || ''
25
+ export const inputMode = $props.inputMode || $props.inputmode || ''
26
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
14
27
  </script>
15
28
 
16
29
  <TextInput
30
+ :name="name"
31
+ :autocomplete="autocomplete"
32
+ :form="form"
33
+ :inputMode="inputMode"
34
+ :enterKeyHint="enterKeyHint"
17
35
  :value="value"
18
36
  :placeholder="placeholder"
19
37
  :disabled="disabled"
@@ -57,6 +57,27 @@ const paddingClasses = showControls ? 'pr-10' : ''
57
57
  export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses} ${paddingClasses} ${inputClassName}`.trim()
58
58
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
59
59
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
60
+ /*
61
+ * The attributes that make this a form control (stacksjs/stx#2043).
62
+ *
63
+ * A control with no `name` is not a form control in the HTML sense: it is left
64
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
65
+ * non-JS POST. A form built from these components submitted nothing for every
66
+ * field, silently -- which is how six apps read their forms.
67
+ *
68
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
69
+ * and a password manager identify a field, so a password input without
70
+ * `autocomplete="current-password"` is never offered for autofill and is not
71
+ * recognised as part of a sign-in form at all.
72
+ *
73
+ * Emitted only when given, so a control that passes none of them renders
74
+ * exactly the markup it did before.
75
+ */
76
+ export const name = $props.name || ''
77
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
78
+ export const form = $props.form || ''
79
+ export const inputMode = $props.inputMode || $props.inputmode || ''
80
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
60
81
  </script>
61
82
 
62
83
  <script client>
@@ -103,6 +124,11 @@ defineExpose({ value: inputValue, increment, decrement })
103
124
 
104
125
  <div class="relative">
105
126
  <input
127
+ @if(name)name="{{ name }}"@endif
128
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
129
+ @if(form)form="{{ form }}"@endif
130
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
131
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
106
132
  type="number"
107
133
  id="{{ inputId }}"
108
134
  class="{{ inputClasses }}"
@@ -56,6 +56,27 @@ export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.m
56
56
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
57
57
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
58
58
  export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
59
+ /*
60
+ * The attributes that make this a form control (stacksjs/stx#2043).
61
+ *
62
+ * A control with no `name` is not a form control in the HTML sense: it is left
63
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
64
+ * non-JS POST. A form built from these components submitted nothing for every
65
+ * field, silently -- which is how six apps read their forms.
66
+ *
67
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
68
+ * and a password manager identify a field, so a password input without
69
+ * `autocomplete="current-password"` is never offered for autofill and is not
70
+ * recognised as part of a sign-in form at all.
71
+ *
72
+ * Emitted only when given, so a control that passes none of them renders
73
+ * exactly the markup it did before.
74
+ */
75
+ export const name = $props.name || ''
76
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
77
+ export const form = $props.form || ''
78
+ export const inputMode = $props.inputMode || $props.inputmode || ''
79
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
59
80
  </script>
60
81
 
61
82
  <script client>
@@ -115,6 +136,11 @@ defineExpose({ value: inputValue })
115
136
 
116
137
  <div class="relative">
117
138
  <input
139
+ @if(name)name="{{ name }}"@endif
140
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
141
+ @if(form)form="{{ form }}"@endif
142
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
143
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
118
144
  :type="inputType()"
119
145
  id="{{ inputId }}"
120
146
  class="{{ inputClasses }}"
@@ -35,6 +35,14 @@ export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-so
35
35
  */
36
36
  export const inputId = $props.id || `radio-${$uid}`
37
37
  export const descriptionId = `${inputId}-description`
38
+ /*
39
+ * `autocomplete` and `form`, alongside the `name` this already had
40
+ * (stacksjs/stx#2043). `autocomplete` is how the browser and a password
41
+ * manager identify a field; `form` lets a control live outside the <form>
42
+ * element it belongs to. Emitted only when given.
43
+ */
44
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
45
+ export const form = $props.form || ''
38
46
  </script>
39
47
 
40
48
  <script client>
@@ -75,6 +83,8 @@ defineExpose({ isChecked })
75
83
  id="{{ inputId }}"
76
84
  type="radio"
77
85
  name="{{ name }}"
86
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
87
+ @if(form)form="{{ form }}"@endif
78
88
  value="{{ value }}"
79
89
  :value="radioValue()"
80
90
  :checked="isChecked()"
@@ -12,6 +12,19 @@ export const className = $props.className || ''
12
12
  export const searchIcon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>'
13
13
  export const spinnerIcon = '<svg class="animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>'
14
14
  export const rightIcon = loading ? spinnerIcon : ''
15
+ /*
16
+ * Forwarded to the TextInput this renders (stacksjs/stx#2043).
17
+ *
18
+ * A wrapper that does not pass them through is as unsubmittable as a control
19
+ * that never accepted them: the inner input is the one that lands in FormData.
20
+ * `type` is the wrapper's own business, but `name`, `autocomplete` and `form`
21
+ * belong to the caller.
22
+ */
23
+ export const name = $props.name || ''
24
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
25
+ export const form = $props.form || ''
26
+ export const inputMode = $props.inputMode || $props.inputmode || ''
27
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
15
28
  </script>
16
29
 
17
30
  <script client>
@@ -28,6 +41,11 @@ function onSearchInput(event) {
28
41
 
29
42
  <div @input="onSearchInput($event)">
30
43
  <TextInput
44
+ :name="name"
45
+ :autocomplete="autocomplete"
46
+ :form="form"
47
+ :inputMode="inputMode"
48
+ :enterKeyHint="enterKeyHint"
31
49
  :value="value"
32
50
  :placeholder="placeholder"
33
51
  :disabled="disabled"
@@ -49,6 +49,25 @@ export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-so
49
49
  */
50
50
  export const selectId = $props.id || `select-${$uid}`
51
51
  export const helperId = `${selectId}-helper`
52
+ /*
53
+ * The attributes that make this a form control (stacksjs/stx#2043).
54
+ *
55
+ * A control with no `name` is not a form control in the HTML sense: it is left
56
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
57
+ * non-JS POST. A form built from these components submitted nothing for every
58
+ * field, silently -- which is how six apps read their forms.
59
+ *
60
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
61
+ * and a password manager identify a field, so a password input without
62
+ * `autocomplete="current-password"` is never offered for autofill and is not
63
+ * recognised as part of a sign-in form at all.
64
+ *
65
+ * Emitted only when given, so a control that passes none of them renders
66
+ * exactly the markup it did before.
67
+ */
68
+ export const name = $props.name || ''
69
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
70
+ export const form = $props.form || ''
52
71
  </script>
53
72
 
54
73
  <script client>
@@ -76,6 +95,9 @@ defineExpose({ value: selectedValue })
76
95
 
77
96
  <div class="{{ label ? 'mt-2' : '' }}">
78
97
  <select
98
+ @if(name)name="{{ name }}"@endif
99
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
100
+ @if(form)form="{{ form }}"@endif
79
101
  id="{{ selectId }}"
80
102
  class="{{ selectClasses }}"
81
103
  :value="selectedValue()"
@@ -1,5 +1,22 @@
1
1
  <script server>
2
2
  export const checked = $bool($props.checked)
3
+
4
+ /*
5
+ * Form participation, which a <button role="switch"> cannot have on its own
6
+ * (stacksjs/stx#2043).
7
+ *
8
+ * The control the user operates is a button, and a button is never submitted
9
+ * by name -- so a Switch inside a form contributed nothing to FormData no
10
+ * matter what it was set to. A hidden input carries the state instead, which
11
+ * is what it takes for a custom switch to be readable the way a checkbox is.
12
+ *
13
+ * Only rendered when a `name` is given, so a Switch used as a plain toggle
14
+ * emits exactly the markup it did before.
15
+ */
16
+ export const name = $props.name || ''
17
+ export const form = $props.form || ''
18
+ export const checkedValue = $props.checkedValue || 'true'
19
+ export const uncheckedValue = $props.uncheckedValue || 'false'
3
20
  export const disabled = $bool($props.disabled)
4
21
  export const size = $props.size || 'md'
5
22
  export const className = $props.className || ''
@@ -60,6 +77,20 @@ defineExpose({ isChecked, toggle })
60
77
  </span>
61
78
  @endif
62
79
 
80
+ @if(name)
81
+ {{-- Always submitted, carrying one of two values, rather than a checkbox's
82
+ present-or-absent convention: a reader then gets an explicit "false"
83
+ instead of a missing key, which is the difference between "switched
84
+ off" and "field was never in the form". --}}
85
+ <input
86
+ type="hidden"
87
+ name="{{ name }}"
88
+ @if(form)form="{{ form }}"@endif
89
+ value="{{ checked ? checkedValue : uncheckedValue }}"
90
+ :value="isChecked() ? '{{ checkedValue }}' : '{{ uncheckedValue }}'"
91
+ />
92
+ @endif
93
+
63
94
  <button
64
95
  type="button"
65
96
  role="switch"
@@ -61,6 +61,27 @@ export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
61
61
  */
62
62
  export const inputId = $props.id || `input-${$uid}`
63
63
  export const helperId = `${inputId}-helper`
64
+ /*
65
+ * The attributes that make this a form control (stacksjs/stx#2043).
66
+ *
67
+ * A control with no `name` is not a form control in the HTML sense: it is left
68
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
69
+ * non-JS POST. A form built from these components submitted nothing for every
70
+ * field, silently -- which is how six apps read their forms.
71
+ *
72
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
73
+ * and a password manager identify a field, so a password input without
74
+ * `autocomplete="current-password"` is never offered for autofill and is not
75
+ * recognised as part of a sign-in form at all.
76
+ *
77
+ * Emitted only when given, so a control that passes none of them renders
78
+ * exactly the markup it did before.
79
+ */
80
+ export const name = $props.name || ''
81
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
82
+ export const form = $props.form || ''
83
+ export const inputMode = $props.inputMode || $props.inputmode || ''
84
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
64
85
  </script>
65
86
 
66
87
  <script client>
@@ -108,6 +129,11 @@ defineExpose({ value: inputValue, clear: onClear })
108
129
  @endif
109
130
 
110
131
  <input
132
+ @if(name)name="{{ name }}"@endif
133
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
134
+ @if(form)form="{{ form }}"@endif
135
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
136
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
111
137
  type="text"
112
138
  id="{{ inputId }}"
113
139
  class="{{ inputClasses }}"
@@ -46,6 +46,27 @@ const disabledClasses = disabled
46
46
  export const textareaClasses = `${baseClasses} ${stateClasses} ${disabledClasses} ${resizeClasses[resize] || resizeClasses.vertical} ${className}`.trim()
47
47
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
48
48
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
49
+ /*
50
+ * The attributes that make this a form control (stacksjs/stx#2043).
51
+ *
52
+ * A control with no `name` is not a form control in the HTML sense: it is left
53
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
54
+ * non-JS POST. A form built from these components submitted nothing for every
55
+ * field, silently -- which is how six apps read their forms.
56
+ *
57
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
58
+ * and a password manager identify a field, so a password input without
59
+ * `autocomplete="current-password"` is never offered for autofill and is not
60
+ * recognised as part of a sign-in form at all.
61
+ *
62
+ * Emitted only when given, so a control that passes none of them renders
63
+ * exactly the markup it did before.
64
+ */
65
+ export const name = $props.name || ''
66
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
67
+ export const form = $props.form || ''
68
+ export const inputMode = $props.inputMode || $props.inputmode || ''
69
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
49
70
  </script>
50
71
 
51
72
  <script client>
@@ -94,6 +115,11 @@ defineExpose({ value: inputValue })
94
115
  @endif
95
116
 
96
117
  <textarea
118
+ @if(name)name="{{ name }}"@endif
119
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
120
+ @if(form)form="{{ form }}"@endif
121
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
122
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
97
123
  id="{{ inputId }}"
98
124
  class="{{ textareaClasses }}"
99
125
  rows="{{ rows }}"