Dojo's Button widget creates a <button> element
- Provides an API for valid
<button>attributes - Can be used to create a toggle button (i.e. a button with an on/off state)
- Provides an easy API to create a button controlling a popup
- The basic button provides a strongly typed
typeproperty, as well asdescribedByanddisabled - Setting
pressedto create a toggle button handlesaria-pressed - Creating a popup button with
popupsetsaria-haspopup,aria-controls, andaria-expanded
// Basic usage
w(Button, {
type: 'submit',
value: 'foo'
}, [ 'Submit' ]);
// Toggle button
// pressed must be a boolean to correctly set aria-pressed
w(Button, {
describedBy: 'instructions',
pressed: !!this.state.buttonPressed,
onClick: (event: MouseEvent) => {
this.setState({ buttonPressed: !this.state.buttonPressed });
}
}, [ 'Click Me' ]),
v('p', {
id: 'instructions'
}, [ 'You can use this pattern to provide extra information, if necessary' ]);
// Button that controls a popup (e.g. a modal or tooltip)
w(Button, {
id: 'foo',
popup: {
id: 'bar',
expanded: this.state.popupOpen
},
onClick: () => {
this.setState({ popupOpen: !this.state.popupOpen });
}
}, [ 'Open Popup' ]),
v('div', {
id: 'bar',
...
}, [ 'Popup Content' ])The following CSS classes are available on the root node of the Button widget for use with custom themes:
root: Always availabledisabled: Applied ifproperties.disabledis truepopup: Applied ifproperties.popuphas a non-false valuepressed: Applied ifproperties.pressedis trueaddon: Applied to the popup icon container ifproperties.popuphas a non-false value