Skip to content

Commit 3168796

Browse files
fix(select): remove options from html markup
1 parent a3a2489 commit 3168796

File tree

1 file changed

+11
-9
lines changed
  • packages/kit-headless/src/components/select

1 file changed

+11
-9
lines changed

packages/kit-headless/src/components/select/select.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ export type SelectProps = PropsOf<'div'> & {
3535

3636
/* root component in select-inline.tsx */
3737
export const SelectImpl = component$<SelectProps>((props: SelectProps) => {
38+
const { _options, ...rest } = props;
39+
3840
// refs
3941
const rootRef = useSignal<HTMLDivElement>();
4042
const triggerRef = useSignal<HTMLButtonElement>();
4143
const popoverRef = useSignal<HTMLElement>();
4244
const listboxRef = useSignal<HTMLUListElement>();
4345
const groupRef = useSignal<HTMLDivElement>();
44-
const loop = props.loop ?? false;
46+
const loop = rest.loop ?? false;
4547
const localId = useId();
4648
const listboxId = `${localId}-listbox`;
4749

@@ -50,21 +52,21 @@ export const SelectImpl = component$<SelectProps>((props: SelectProps) => {
5052
* (for example, when a new option is added)
5153
**/
5254
const optionsSig = useComputed$(() => {
53-
if (props._options === undefined || props._options.length === 0) {
55+
if (_options === undefined || _options.length === 0) {
5456
return [];
5557
}
56-
return props._options;
58+
return _options;
5759
});
5860

5961
const optionsIndexMap = new Map(
6062
optionsSig.value?.map((option, index) => [option.value, index]),
6163
);
6264

6365
// core state
64-
const selectedIndexSig = useSignal<number | null>(props._valuePropIndex ?? null);
65-
const highlightedIndexSig = useSignal<number | null>(props._valuePropIndex ?? null);
66+
const selectedIndexSig = useSignal<number | null>(rest._valuePropIndex ?? null);
67+
const highlightedIndexSig = useSignal<number | null>(rest._valuePropIndex ?? null);
6668
const isListboxOpenSig = useSignal<boolean>(false);
67-
const scrollOptions = props.scrollOptions ?? {
69+
const scrollOptions = rest.scrollOptions ?? {
6870
behavior: 'instant',
6971
block: 'nearest',
7072
};
@@ -84,15 +86,15 @@ export const SelectImpl = component$<SelectProps>((props: SelectProps) => {
8486
useTask$(async function onChangeTask({ track }) {
8587
track(() => selectedIndexSig.value);
8688
if (isBrowser && selectedIndexSig.value !== null) {
87-
await props.onChange$?.(optionsSig.value[selectedIndexSig.value!].value);
89+
await rest.onChange$?.(optionsSig.value[selectedIndexSig.value!].value);
8890
}
8991
});
9092

9193
useTask$(function onOpenChangeTask({ track }) {
9294
track(() => isListboxOpenSig.value);
9395

9496
if (isBrowser) {
95-
props.onOpenChange$?.();
97+
rest.onOpenChange$?.();
9698
}
9799
});
98100

@@ -130,7 +132,7 @@ export const SelectImpl = component$<SelectProps>((props: SelectProps) => {
130132
aria-controls={listboxId}
131133
aria-expanded={context.isListboxOpenSig.value}
132134
aria-haspopup="listbox"
133-
{...props}
135+
{...rest}
134136
>
135137
<Slot />
136138
</div>

0 commit comments

Comments
 (0)