Skip to content

Commit 80b9a7f

Browse files
committed
style(select): update variable names to be more explicit
1 parent bc08c54 commit 80b9a7f

File tree

9 files changed

+60
-68
lines changed

9 files changed

+60
-68
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { QRL, Signal } from '@builder.io/qwik';
1+
import { Signal } from '@builder.io/qwik';
22

33
export type SelectContext = {
4-
options: HTMLElement[];
5-
selection: Signal<string | undefined>;
6-
isExpanded: Signal<boolean>;
7-
triggerRef: Signal<HTMLElement | undefined>;
8-
listBoxRef: Signal<HTMLElement | undefined>;
4+
optionsStore: HTMLElement[];
5+
selectedOptionSig: Signal<string | undefined>;
6+
isOpenSig: Signal<boolean>;
7+
triggerRefSig: Signal<HTMLElement | undefined>;
8+
listBoxRefSig: Signal<HTMLElement | undefined>;
99
};
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import { QwikIntrinsicElements, Slot, component$ } from '@builder.io/qwik';
1+
import { component$, QwikIntrinsicElements, Slot } from '@builder.io/qwik';
22

33
export type SelectGroupProps = {
44
disabled?: boolean;
55
} & QwikIntrinsicElements['div'];
66

7-
export const SelectGroup = component$(
8-
({ disabled, ...props }: SelectGroupProps) => {
9-
return (
10-
<div role="group" aria-disabled={disabled} {...props}>
11-
<Slot />
12-
</div>
13-
);
14-
}
15-
);
7+
export const SelectGroup = component$(({ disabled, ...props }: SelectGroupProps) => {
8+
return (
9+
<div role="group" aria-disabled={disabled} {...props}>
10+
<Slot />
11+
</div>
12+
);
13+
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export type SelectListBoxProps = QwikIntrinsicElements['ul'];
1313
export const SelectListBox = component$((props: SelectListBoxProps) => {
1414
const listBoxRef = useSignal<HTMLElement>();
1515
const selectContext = useContext(SelectContextId);
16-
selectContext.listBoxRef = listBoxRef;
16+
selectContext.listBoxRefSig = listBoxRef;
1717

1818
useVisibleTask$(function setKeyHandler({ cleanup }) {
1919
function keyHandler(e: KeyboardEvent) {
20-
const availableOptions = selectContext.options.filter(
20+
const availableOptions = selectContext.optionsStore.filter(
2121
(option) => !(option?.getAttribute('aria-disabled') === 'true')
2222
);
2323
const target = e.target as HTMLElement;
@@ -61,7 +61,7 @@ export const SelectListBox = component$((props: SelectListBoxProps) => {
6161
role="listbox"
6262
tabIndex={0}
6363
style={`
64-
display: ${selectContext.isExpanded.value ? 'block' : 'none'};
64+
display: ${selectContext.isOpenSig.value ? 'block' : 'none'};
6565
position: absolute;
6666
z-index: 1;
6767
${props.style}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QwikIntrinsicElements, Slot, component$ } from '@builder.io/qwik';
1+
import { component$, QwikIntrinsicElements, Slot } from '@builder.io/qwik';
22

33
export type SelectMarkerProps = QwikIntrinsicElements['span'];
44

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const NativeSelect = component$(
1010
const ref = useSignal<HTMLElement>();
1111

1212
useVisibleTask$(function populateNativeSelect({ track }) {
13-
const options = track(() => selectContext.options);
13+
const options = track(() => selectContext.optionsStore);
1414

1515
options.length > 0 &&
1616
options.map((option) => {
@@ -25,7 +25,7 @@ export const NativeSelect = component$(
2525
'change',
2626
$((e) => {
2727
const target = e.target as HTMLSelectElement;
28-
target.value = selectContext.selection.value!;
28+
target.value = selectContext.selectedOptionSig.value!;
2929
})
3030
);
3131

@@ -35,7 +35,7 @@ export const NativeSelect = component$(
3535
required
3636
aria-hidden
3737
tabIndex={-1}
38-
bind:value={selectContext.selection}
38+
bind:value={selectContext.selectedOptionSig}
3939
{...props}
4040
>
4141
<option value="" />

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ export const SelectOption = component$(
3131
}
3232

3333
if (!disabled && e.key === 'Tab' && target.dataset.optionValue === optionValue) {
34-
selectContext.selection.value = optionValue;
35-
selectContext.isExpanded.value = false;
34+
selectContext.selectedOptionSig.value = optionValue;
35+
selectContext.isOpenSig.value = false;
3636
}
3737

3838
if (
3939
!disabled &&
4040
(e.key === 'Enter' || e.key === ' ') &&
4141
target.dataset.optionValue === optionValue
4242
) {
43-
selectContext.selection.value = optionValue;
44-
selectContext.isExpanded.value = false;
43+
selectContext.selectedOptionSig.value = optionValue;
44+
selectContext.isOpenSig.value = false;
4545
}
4646
}
4747
optionRef.value?.addEventListener('keydown', keyHandler);
@@ -56,12 +56,12 @@ export const SelectOption = component$(
5656
role="option"
5757
tabIndex={disabled ? -1 : 0}
5858
aria-disabled={disabled}
59-
aria-selected={optionValue === selectContext.selection.value}
59+
aria-selected={optionValue === selectContext.selectedOptionSig.value}
6060
data-option-value={optionValue}
6161
onClick$={() => {
6262
if (!disabled) {
63-
selectContext.selection.value = optionValue;
64-
selectContext.isExpanded.value = false;
63+
selectContext.selectedOptionSig.value = optionValue;
64+
selectContext.isOpenSig.value = false;
6565
}
6666
}}
6767
onMouseEnter$={(e) => {

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ export type SelectRootProps = {
2020
} & QwikIntrinsicElements['div'];
2121

2222
export const SelectRoot = component$((props: SelectRootProps) => {
23-
const rootRef = useSignal<HTMLElement>();
24-
const options = useStore([]);
25-
const selection = useSignal('');
26-
const isExpanded = useSignal(false);
27-
const triggerRef = useSignal<HTMLElement>();
28-
const listBoxRef = useSignal<HTMLElement>();
23+
const rootRefSig = useSignal<HTMLElement>();
24+
const optionsStore = useStore([]);
25+
const selectedOptionSig = useSignal('');
26+
const isOpenSig = useSignal(false);
27+
const triggerRefSig = useSignal<HTMLElement>();
28+
const listBoxRefSig = useSignal<HTMLElement>();
2929

3030
const selectContext: SelectContext = {
31-
options,
32-
selection,
33-
isExpanded,
34-
triggerRef,
35-
listBoxRef
31+
optionsStore,
32+
selectedOptionSig,
33+
isOpenSig,
34+
triggerRefSig,
35+
listBoxRefSig
3636
};
3737

3838
useContextProvider(SelectContextId, selectContext);
@@ -41,8 +41,8 @@ export const SelectRoot = component$((props: SelectRootProps) => {
4141
'click',
4242
$((e) => {
4343
const target = e.target as HTMLElement;
44-
if (selectContext.isExpanded.value === true && !rootRef.value?.contains(target)) {
45-
selectContext.isExpanded.value = false;
44+
if (selectContext.isOpenSig.value === true && !rootRefSig.value?.contains(target)) {
45+
selectContext.isOpenSig.value = false;
4646
}
4747
})
4848
);
@@ -51,12 +51,12 @@ export const SelectRoot = component$((props: SelectRootProps) => {
5151
function keyHandler(e: KeyboardEvent) {
5252
e.preventDefault();
5353
if (e.key === 'Escape') {
54-
selectContext.isExpanded.value = false;
54+
selectContext.isOpenSig.value = false;
5555
}
5656
}
57-
rootRef.value?.addEventListener('keydown', keyHandler);
57+
rootRefSig.value?.addEventListener('keydown', keyHandler);
5858
cleanup(() => {
59-
rootRef.value?.removeEventListener('keydown', keyHandler);
59+
rootRefSig.value?.removeEventListener('keydown', keyHandler);
6060
});
6161
});
6262

@@ -73,9 +73,9 @@ export const SelectRoot = component$((props: SelectRootProps) => {
7373
});
7474

7575
useVisibleTask$(async function toggleSelectListBox({ track }) {
76-
const trigger = track(() => selectContext.triggerRef.value);
77-
const listBox = track(() => selectContext.listBoxRef.value);
78-
const expanded = track(() => selectContext.isExpanded.value);
76+
const trigger = track(() => selectContext.triggerRefSig.value);
77+
const listBox = track(() => selectContext.listBoxRefSig.value);
78+
const expanded = track(() => selectContext.isOpenSig.value);
7979

8080
if (!trigger || !listBox) return;
8181

@@ -92,18 +92,18 @@ export const SelectRoot = component$((props: SelectRootProps) => {
9292
});
9393

9494
useVisibleTask$(function collectOptions({ track }) {
95-
const listBox = track(() => selectContext.listBoxRef.value);
95+
const listBox = track(() => selectContext.listBoxRefSig.value);
9696

9797
if (listBox) {
9898
const collectedOptions = Array.from(
9999
listBox.querySelectorAll('[role="option"]')
100100
) as HTMLElement[];
101-
selectContext.options.push(...collectedOptions);
101+
selectContext.optionsStore.push(...collectedOptions);
102102
}
103103
});
104104

105105
return (
106-
<div ref={rootRef} {...props}>
106+
<div ref={rootRefSig} {...props}>
107107
<Slot />
108108
{props.required ? (
109109
<VisuallyHidden>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export type SelectTriggerProps = QwikIntrinsicElements['button'];
1313
export const SelectTrigger = component$((props: SelectTriggerProps) => {
1414
const selectContext = useContext(SelectContextId);
1515
const triggerRef = useSignal<HTMLElement>();
16-
selectContext.triggerRef = triggerRef;
16+
selectContext.triggerRefSig = triggerRef;
1717

1818
useVisibleTask$(function setClickHandler({ cleanup }) {
1919
function clickHandler(e: Event) {
2020
e.preventDefault();
21-
selectContext.isExpanded.value = !selectContext.isExpanded.value;
21+
selectContext.isOpenSig.value = !selectContext.isOpenSig.value;
2222
}
2323
triggerRef.value?.addEventListener('click', clickHandler);
2424
cleanup(() => {
@@ -37,7 +37,7 @@ export const SelectTrigger = component$((props: SelectTriggerProps) => {
3737
e.key === 'Enter' ||
3838
e.key === ' '
3939
) {
40-
selectContext.isExpanded.value = true;
40+
selectContext.isOpenSig.value = true;
4141
}
4242
}
4343
triggerRef.value?.addEventListener('keydown', keyHandler);
@@ -47,7 +47,7 @@ export const SelectTrigger = component$((props: SelectTriggerProps) => {
4747
});
4848

4949
return (
50-
<button ref={triggerRef} aria-expanded={selectContext.isExpanded.value} {...props}>
50+
<button ref={triggerRef} aria-expanded={selectContext.isOpenSig.value} {...props}>
5151
<Slot />
5252
</button>
5353
);
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import {
2-
QwikIntrinsicElements,
3-
component$,
4-
useContext,
5-
} from '@builder.io/qwik';
1+
import { component$, QwikIntrinsicElements, useContext } from '@builder.io/qwik';
62
import SelectContextId from './select-context-id';
73

84
export type SelectValueProps = {
95
placeholder?: string;
106
} & QwikIntrinsicElements['span'];
117

12-
export const SelectValue = component$(
13-
({ placeholder, ...props }: SelectValueProps) => {
14-
const selectContext = useContext(SelectContextId);
15-
const value = selectContext.selection.value;
16-
return <span {...props}>{value ? value : placeholder}</span>;
17-
}
18-
);
8+
export const SelectValue = component$(({ placeholder, ...props }: SelectValueProps) => {
9+
const selectContext = useContext(SelectContextId);
10+
const value = selectContext.selectedOptionSig.value;
11+
return <span {...props}>{value ? value : placeholder}</span>;
12+
});

0 commit comments

Comments
 (0)