x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<div class="tw:p-6 tw:max-w-7xl tw:mx-auto tw:space-y-8"> <div class="callout"> <p class="tw:mb-1 tw:text-sm tw:font-mono"> <strong>STARS INPUT:</strong> Interactive 5-star rating radiogroup<br> <strong>COMPOSES:</strong> .stars color tokens (save-yellow) | native radio group (keyboard + AT for free) </p> <p class="tw:mb-0 tw:text-sm"> Each star is a real radio input, visually hidden inside its own label — Arrow keys move between stars and select as you go, Tab moves in/out of the group as one stop, and Space selects the focused star. <code>stars_input_controller.js</code> only keeps the fill in sync (hover preview, native <code>change</code>) and, when explicitly opted in via <code>data-stars-input-clearable-value="true"</code>, adds one thing radios can't do alone: activating the already-selected star a second time (click <em>or</em> Space) clears the rating back to blank. Off by default — see the dedicated "Clearable" scenario below. </p> </div> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Blank</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Unrated:</strong> no radio is checked. Hover or tab in to preview a rating; click or press Space on a star to commit it. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-blank-label">Teaching quality</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-blank-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> <p class="form-text">Rate how satisfied you were with the teaching quality.</p> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars-input" role="radiogroup" aria-labelledby="…" data-controller="stars-input"><label class="stars-input-star" data-value="1"><input type="radio" class="tw:sr-only" aria-label="1 star"><i class="fa-light fa-star"></i></label>…</div></code> </div> </div> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Preset (4 of 5)</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Pre-filled from data:</strong> the 4th radio carries <code>checked</code> in the markup — <code>connect()</code> reads it and fills stars 1–4 on load, no click required. This scenario is <strong>not clearable</strong> (the default) — once set, a rating can only be changed to a different star, matching plain native radiogroup behavior. See the "Clearable" scenario below for the opt-in clear-on-reclick behavior. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-preset-label">Communication with parents</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-preset-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="4" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> </div> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Clearable</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>data-stars-input-clearable-value="true":</strong> explicit opt-in. Click (or press Space on) the already-selected star a second time to clear the rating back to blank — the one thing a plain radiogroup can't do on its own. Works identically from mouse and keyboard; either way the controller fires a genuine <code>change</code> event on the underlying radio so form logic and assistive tech see the clear, not just this controller's own <code>stars-input:changed</code> event. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-clearable-label">Overall experience</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-clearable-label" data-controller="stars-input" data-stars-input-clearable-value="true" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="1" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> <p class="form-text">Click your rating again to clear it.</p> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars-input" role="radiogroup" data-controller="stars-input" data-stars-input-clearable-value="true">…</div></code> </div> </div> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Sizes</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>.stars-input-sm / .stars-input-lg:</strong> same behaviour, smaller/larger glyph and gap. Default sits between the two. </p> </div> <div class="tw:flex tw:flex-wrap tw:items-end tw:gap-8"> <div> <label class="form-label form-label-sm" id="rating-sm-label">Compact (list row)</label> <div class="stars-input stars-input-sm" role="radiogroup" aria-labelledby="rating-sm-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="2" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> <div> <label class="form-label form-label-lg" id="rating-lg-label">Large (review form)</label> <div class="stars-input stars-input-lg" role="radiogroup" aria-labelledby="rating-lg-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="3" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> </div> </div> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Read-only display</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Not a disabled .stars-input:</strong> once a rating is submitted and only ever displayed (a review card, a summary table), use the read-only <code>.stars</code> component instead of a locked interactive radiogroup — it needs no controller and carries a plain <code>aria-label</code> rather than five named radios. </p> </div> <div class="stars" role="img" aria-label="4 out of 5 stars"> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-light fa-star" aria-hidden="true"></i> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars" role="img" aria-label="4 out of 5 stars">…</div></code> </div> </div></div>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<div class="tw:p-6 tw:max-w-7xl tw:mx-auto tw:space-y-8"> <%# Introductory callout %> <div class="callout"> <p class="tw:mb-1 tw:text-sm tw:font-mono"> <strong>STARS INPUT:</strong> Interactive 5-star rating radiogroup<br> <strong>COMPOSES:</strong> .stars color tokens (save-yellow) | native radio group (keyboard + AT for free) </p> <p class="tw:mb-0 tw:text-sm"> Each star is a real radio input, visually hidden inside its own label — Arrow keys move between stars and select as you go, Tab moves in/out of the group as one stop, and Space selects the focused star. <code>stars_input_controller.js</code> only keeps the fill in sync (hover preview, native <code>change</code>) and, when explicitly opted in via <code>data-stars-input-clearable-value="true"</code>, adds one thing radios can't do alone: activating the already-selected star a second time (click <em>or</em> Space) clears the rating back to blank. Off by default — see the dedicated "Clearable" scenario below. </p> </div> <%# Blank %> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Blank</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Unrated:</strong> no radio is checked. Hover or tab in to preview a rating; click or press Space on a star to commit it. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-blank-label">Teaching quality</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-blank-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-blank" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> <p class="form-text">Rate how satisfied you were with the teaching quality.</p> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars-input" role="radiogroup" aria-labelledby="…" data-controller="stars-input"><label class="stars-input-star" data-value="1"><input type="radio" class="tw:sr-only" aria-label="1 star"><i class="fa-light fa-star"></i></label>…</div></code> </div> </div> <%# Preset value %> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Preset (4 of 5)</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Pre-filled from data:</strong> the 4th radio carries <code>checked</code> in the markup — <code>connect()</code> reads it and fills stars 1–4 on load, no click required. This scenario is <strong>not clearable</strong> (the default) — once set, a rating can only be changed to a different star, matching plain native radiogroup behavior. See the "Clearable" scenario below for the opt-in clear-on-reclick behavior. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-preset-label">Communication with parents</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-preset-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="4" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-preset" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> </div> <%# Clearable — opt-in %> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Clearable</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>data-stars-input-clearable-value="true":</strong> explicit opt-in. Click (or press Space on) the already-selected star a second time to clear the rating back to blank — the one thing a plain radiogroup can't do on its own. Works identically from mouse and keyboard; either way the controller fires a genuine <code>change</code> event on the underlying radio so form logic and assistive tech see the clear, not just this controller's own <code>stars-input:changed</code> event. </p> </div> <div class="tw:max-w-sm"> <label class="form-label" id="rating-clearable-label">Overall experience</label> <div class="stars-input" role="radiogroup" aria-labelledby="rating-clearable-label" data-controller="stars-input" data-stars-input-clearable-value="true" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="1" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-clearable" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> <p class="form-text">Click your rating again to clear it.</p> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars-input" role="radiogroup" data-controller="stars-input" data-stars-input-clearable-value="true">…</div></code> </div> </div> <%# Sizes %> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Sizes</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>.stars-input-sm / .stars-input-lg:</strong> same behaviour, smaller/larger glyph and gap. Default sits between the two. </p> </div> <div class="tw:flex tw:flex-wrap tw:items-end tw:gap-8"> <div> <label class="form-label form-label-sm" id="rating-sm-label">Compact (list row)</label> <div class="stars-input stars-input-sm" role="radiogroup" aria-labelledby="rating-sm-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="2" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="3" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-sm" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> <div> <label class="form-label form-label-lg" id="rating-lg-label">Large (review form)</label> <div class="stars-input stars-input-lg" role="radiogroup" aria-labelledby="rating-lg-label" data-controller="stars-input" data-action="mouseleave->stars-input#resetPreview"> <label class="stars-input-star" data-stars-input-target="star" data-value="1" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="1" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="1 star"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="2" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="2" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="2 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="3" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="3" class="tw:sr-only" checked data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="3 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="4" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="4" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="4 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> <label class="stars-input-star" data-stars-input-target="star" data-value="5" data-action="mouseenter->stars-input#preview mousedown->stars-input#trackClick click->stars-input#clearIfRepeat"> <input type="radio" name="rating-lg" value="5" class="tw:sr-only" data-stars-input-target="input" data-action="change->stars-input#onChange keydown->stars-input#clearOnSpace" aria-label="5 stars"> <i class="fa-light fa-star" aria-hidden="true"></i> </label> </div> </div> </div> </div> <%# Read-only / disabled — points to .stars %> <div class="tw:border-t tw:pt-6"> <h2 class="h4 tw:mb-4">Read-only display</h2> <div class="callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Not a disabled .stars-input:</strong> once a rating is submitted and only ever displayed (a review card, a summary table), use the read-only <code>.stars</code> component instead of a locked interactive radiogroup — it needs no controller and carries a plain <code>aria-label</code> rather than five named radios. </p> </div> <div class="stars" role="img" aria-label="4 out of 5 stars"> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-solid fa-star" aria-hidden="true"></i> <i class="fa-light fa-star" aria-hidden="true"></i> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="stars" role="img" aria-label="4 out of 5 stars">…</div></code> </div> </div></div>No notes provided.
No params configured.