Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox Group widget #797

Closed
Tracked by #780
tomdye opened this issue Sep 24, 2019 · 0 comments · Fixed by #803
Closed
Tracked by #780

Checkbox Group widget #797

tomdye opened this issue Sep 24, 2019 · 0 comments · Fixed by #803

Comments

@tomdye
Copy link
Member

tomdye commented Sep 24, 2019

The checkbox group widget will control a number of dojo checkboxes allowing them to behave like native html check boxes.

This would mean setting the same name property of each of the child checkboxes and controlling the checked property of each. Setting the name and value properties of the checkboxes is very important to make this work.

The checkboxes should probably be wrapped in a fieldset and the group widget should accept a label property that gets used as a legend for the fieldset.

There are several ways we might approach this:

middleware

A checkbox group middleware could be used for a functional widget approach. The middleware could provide a getter and setter for the checkbox group value. This would then be used to set the checked status of the widgets.

const factory = create({ checkboxGroup }).properties();
export const ProviderBrowse = factory(function ProviderBrowse({
	middleware: { checkboxGroup }
}) {
	const { name, getValue, setValue } = checkboxGroup;
	
	return [
		<Checkbox value="dog" name={name} checked={() => {getValue('dog')}} onValue={(checked) => {setValue(checked, 'dog')}}/>,
		<Checkbox value="cat" name={name} checked={() => {getValue('cat')}} onValue={(checked) => {setValue(checked, 'cat')}}/>,
		<Checkbox value="fish" name={name} checked={() => {getValue('fish')}} onValue={(checked) => {setValue(checked, 'fish')}}/>
	];
});

renderprops

A render prop could be used to render the child checkboxes. It would make an onValueChange property available to the child checkboxes which they could use to report back their value on change.

<CheckboxGroup value={['dog']} renderCheckboxes={(name, onValue) => [
	<Checkbox value="dog" name={name} onValue={(checked) => {onValue(checked, 'dog')}}/>,
	<Checkbox value="cat" name={name} onValue={(checked) => {onValue(checked, 'cat')}}/>,
	<Checkbox value="fish" name={name} onValue={(checked) => {onValue(checked, 'fish')}}/>
]} />

child checkboxes

The checkbox group widget could take checkbox widgets as it's children. These could then be auto wired up to the get and set value functions of the group.

import { CheckboxGroup } from 'CheckboxGroup';
import { Checkbox } from 'Checkbox';

<CheckboxGroup value={['dog']} >
	<Checkbox value="dog" />
	<Checkbox value="cat" />
	<Checkbox value="fish" />
</CheckboxGroup>

child checkbox factory functions

The checkbox group widget could export a factory function that's used to create the child checkboxes. This would restrict access to the check box properties and give the parent group access to the created widget onValue callbacks.

import { CheckboxGroup, createCheckBox } from 'CheckboxGroup';

<CheckboxGroup label="pets" value={['dog']} >
	createCheckBox("dog")
	createCheckBox("cat")
	createCheckBox("fish")
</CheckboxGroup>
@tomdye tomdye mentioned this issue Sep 24, 2019
47 tasks
@tomdye tomdye changed the title Radio Group widget Checkbox Group widget Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant