MCPcopy Create free account
hub / github.com/kobaltedev/kobalte / HTMLFormExample

Function HTMLFormExample

apps/docs/src/examples/radio-group.tsx:153–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

151}
152
153export function HTMLFormExample() {
154 let formRef: HTMLFormElement | undefined;
155
156 const onSubmit = (e: SubmitEvent) => {
157 e.preventDefault();
158 e.stopPropagation();
159
160 const formData = new FormData(formRef);
161
162 alert(JSON.stringify(Object.fromEntries(formData), null, 2));
163 };
164
165 return (
166 <form
167 ref={formRef}
168 onSubmit={onSubmit}
169 class="flex flex-col items-center space-y-6"
170 >
171 <RadioGroup class={style["radio-group"]} name="favorite-fruit">
172 <RadioGroup.Label class={style["radio-group__label"]}>
173 Favorite fruit
174 </RadioGroup.Label>
175 <div class={style["radio-group__items"]} role="presentation">
176 <For each={["Apple", "Orange", "Watermelon"]}>
177 {(fruit) => (
178 <RadioGroup.Item value={fruit} class={style.radio}>
179 <RadioGroup.ItemInput class={style.radio__input} />
180 <RadioGroup.ItemControl class={style.radio__control}>
181 <RadioGroup.ItemIndicator class={style.radio__indicator} />
182 </RadioGroup.ItemControl>
183 <RadioGroup.ItemLabel class={style.radio__label}>
184 {fruit}
185 </RadioGroup.ItemLabel>
186 </RadioGroup.Item>
187 )}
188 </For>
189 </div>
190 </RadioGroup>
191 <div class="flex space-x-2">
192 <button type="reset" class="kb-button">
193 Reset
194 </button>
195 <button type="submit" class="kb-button-primary">
196 Submit
197 </button>
198 </div>
199 </form>
200 );
201}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected