You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find myself having to manually implement a toggle all checkbox as part of a set. This would be a good candidate for a feature option.
Here's my current implementation for a component that selects from a list of groups:
import{useGroupList}from"@/hooks/useGroupList"import{CheckboxField,CheckboxSetField,Item}from"@osuresearch/ui";importReact,{useState}from"react";exporttypeGroupSelectFieldProps={value?: string[]onChange: (ids: string[]|undefined)=>voidselectAllLabel: React.ReactNode}/** * Allows the user to select one or more groups from * the list of all groups they have access to. */exportfunctionGroupSelectField({ value, selectAllLabel, onChange }: GroupSelectFieldProps){const{ groups, loading, error }=useGroupList();if(!groups){returnnull;}consthandleChange=(ids?: string[])=>{onChange(ids);}consthasSelection=value&&value.length>0;consthasPartialSelection=hasSelection&&value.length!==groups.length;consttoggleAll=(on?: boolean)=>{if(hasSelection&&value.length===groups.length){onChange(undefined);}else{onChange(groups.map((g)=>g.id));}}return(<div><CheckboxFieldname="all-groups"value={value ? value.length>0 : false}isIndeterminate={hasPartialSelection}onChange={toggleAll}label={selectAllLabel}/><CheckboxSetFieldpt="sm"pl="xl"name="groups"value={value??[]}onChange={handleChange}aria-label="Select one or more groups">{groups.map((group)=><Itemkey={group.id}>{group.id}</Item>)}</CheckboxSetField></div>)}
Visually it looks something like the following:
The text was updated successfully, but these errors were encountered:
I find myself having to manually implement a toggle all checkbox as part of a set. This would be a good candidate for a feature option.
Here's my current implementation for a component that selects from a list of groups:
Visually it looks something like the following:
The text was updated successfully, but these errors were encountered: