Tracks the active status of child Activatable components.
This component is a Context Provider,
it does not render any elements.
This component can be used to build accordions, tabs, toggle buttons, offscreen navs, and any other component that toggles an on/off state.
<Activatables>
<Activatableid="1">
{({ active, toggleActive })=>(
<ButtononClick={toggleActive}>
Button 1A {active ?'on':'off'}
</Button>
)}
</Activatable>
<Activatableid="1">
{({ active, toggleActive })=>(
<ButtononClick={toggleActive}>
Button 1B {active ?'on':'off'}
</Button>
)}
</Activatable>
<Activatableid="2">
{({ active, toggleActive })=>(
<ButtononClick={toggleActive}>
Button 2{active ?'on':'off'}
</Button>
)}
</Activatable>
</Activatables>
Live Demo
defaultActiveIds
An array of ids to default to active.
allowMultipleActive
Allows multiple ids to be active simultaneously. Defaults to false.
allowNoneActive
Allows all ids to be inactive simultaneously. Defaults to true.
<Activatables
defaultActiveIds={['1']}
allowMultipleActive
allowNoneActive={false}
>
<Activatableid="1">
{({ active, toggleActive })=>(
<ButtononClick={toggleActive}>
Button 1{active ?'on':'off'}
</Button>
)}
</Activatable>
<Activatableid="2">
{({ active, toggleActive })=>(
<ButtononClick={toggleActive}>
Button 2{active ?'on':'off'}
</Button>
)}
</Activatable>
</Activatables>
Live Demo
Activatable child
Each child Activatable component must have an id, which is used to track its active state. Multiple
Activatable components can have the same id, and ids may be strings or numbers.
The Activatable component wraps a child function which receives a props object: