Skip to content

Commit a1f1392

Browse files
committed
FIX: added conditional to prevent reducing on empty array
1 parent 10dedf2 commit a1f1392

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

apps/website/src/routes/docs/headless/checkbox/examples/hero.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default component$(() => {
77
<CheckboxIndicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
88
99
</CheckboxIndicator>
10-
No other stuff is needed here
10+
Accept item
1111
</MyCheckbox>
1212
</>
1313
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import { MyCheckbox, CheckboxIndicator, CheckList } from '@qwik-ui/headless';
3+
export default component$(() => {
4+
return (
5+
<>
6+
<h3 id="pizza-toppings">Pizza toppings</h3>
7+
<CheckList ariaLabeledBy="pizza-toppings">
8+
<MyCheckbox
9+
class="flex items-center gap-3 border-2 border-black p-2 "
10+
checkList={true}
11+
>
12+
<CheckboxIndicator class="flex h-[25px] w-[25px] items-center justify-center bg-slate-600">
13+
14+
</CheckboxIndicator>
15+
Pick all toppings
16+
</MyCheckbox>
17+
</CheckList>
18+
</>
19+
);
20+
});

apps/website/src/routes/docs/headless/checkbox/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ import { statusByComponent } from '~/_state/component-statuses';
1212
Gives users a visual representation of what options they have picked and those that they have not by "checking" each option they want.
1313

1414
<Showcase name="hero" />
15+
<Showcase name="pizza" />

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ export const TriStateCheckbox = component$<TriStateCheckboxProps>((props) => {
150150
const checklistContext = useContext(CheckListContext);
151151
const childCheckboxes = checklistContext.checkboxes;
152152
const appliedSig = props.checkBoxSig ?? checklistContext.checklistSig;
153-
const ariaControlsStrg = checklistContext.idArr.reduce((p, c) => p + ' ' + c);
153+
const ariaControlsStrg =
154+
checklistContext.idArr.length === 0
155+
? ''
156+
: checklistContext.idArr.reduce((p, c) => p + ' ' + c);
154157
useContextProvider(CheckboxContext, appliedSig);
155158
useTask$(() => {});
156159

packages/kit-headless/src/components/checkbox/checklist.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ export const CheckList: Component<CheckListProps> = (props: CheckListProps) => {
8484
checklistChilds.forEach((checkbox) => {
8585
Object.assign(checkbox.props, { _overWriteCheckbox: true });
8686
});
87-
// TODO: add code for controlled stuff
88-
// for (let index = 0; index < hellSigs.length; index++) {
89-
// const element = array[index];
90-
//
91-
// }
9287
}
9388
console.log('fav idArr: ', idArr);
9489

@@ -110,3 +105,4 @@ export const CheckList: Component<CheckListProps> = (props: CheckListProps) => {
110105
</>
111106
);
112107
};
108+
// TODO: deprecate ariaLabelledBy

0 commit comments

Comments
 (0)