Introduction
Checkboxes are a great way to choose one or multiple options within many choices. Office UI Fabric/Flunet UI controls provides the simplest checkbox implementation that can be used in the SharePoint Framework. When clicked, the checkbox fires the "onChange" event. However, grouping them is a challenge.
In this article, we will explore dynamically grouping the checkboxes, and handle the selection event for them.
Checkbox implementation in SPFx
Imports for Checkbox control:
- import { Checkbox} from 'office-ui-fabric-react/lib/Checkbox';
Use Checkbox in render method.
- <Checkbox label="Choices" onChange={_onChange} />
The onChange is invoked on Checkbox’s value change.
- function _onChange(ev: React.FormEvent<HTMLElement>, isChecked: boolean) {
- console.log(“The selection ${isChecked}.”);
- }
Now, when we check/uncheck the Checkbox, it fires the onChange event which helps detect the changed value. We can have multiple checkboxes, each implementing an onChange event.
Dynamic Checkboxes
In the real world, we have to dynamically create Checkboxes and group them based on the business logic.
Let us consider the below data to build dynamic Checkboxes.
- const options: ICheckboxInput[] = [
- { ID: 1, Title: 'Apple' },
- { ID: 2, Title: 'Banana' },
- { ID: 3, Title: 'Fig' },
- { ID: 4, Title: 'Grape' },
- { ID: 5, Title: 'Kiwi' },
- { ID: 6, Title: 'Melon' },
- { ID: 7, Title: 'Orange' },
- { ID: 8, Title: 'Pineapple' }
- ];


Join the conversation! Your thoughts help the community grow.