2017-03-03 17:54:46 +00:00
## Class: TouchBarButton
> Create a button in the touch bar for native macOS applications
2021-06-15 20:50:31 +00:00
Process: [Main ](../glossary.md#main-process )< br />
_This class is not exported from the `'electron'` module. It is only available as a return value of other methods in the Electron API._
2017-03-03 17:54:46 +00:00
2020-04-02 16:32:18 +00:00
### `new TouchBarButton(options)`
2017-03-03 17:54:46 +00:00
* `options` Object
* `label` String (optional) - Button text.
2019-10-08 15:13:57 +00:00
* `accessibilityLabel` String (optional) - A short description of the button for use by screenreaders like VoiceOver.
2017-03-03 17:54:46 +00:00
* `backgroundColor` String (optional) - Button background color in hex format,
i.e `#ABCDEF` .
2019-07-25 18:30:42 +00:00
* `icon` [NativeImage ](native-image.md ) | String (optional) - Button icon.
2019-08-01 14:59:26 +00:00
* `iconPosition` String (optional) - Can be `left` , `right` or `overlay` . Defaults to `overlay` .
2017-03-03 17:54:46 +00:00
* `click` Function (optional) - Function to call when the button is clicked.
2019-11-05 23:56:36 +00:00
* `enabled` Boolean (optional) - Whether the button is in an enabled state. Default is `true` .
2017-03-03 17:54:46 +00:00
2019-10-08 15:13:57 +00:00
When defining `accessibilityLabel` , ensure you have considered macOS [best practices ](https://developer.apple.com/documentation/appkit/nsaccessibilitybutton/1524910-accessibilitylabel?language=objc ).
2017-03-03 17:54:46 +00:00
### Instance Properties
The following properties are available on instances of `TouchBarButton` :
2019-10-08 15:13:57 +00:00
#### `touchBarButton.accessibilityLabel`
A `String` representing the description of the button to be read by a screen reader. Will only be read by screen readers if no label is set.
2017-03-03 17:54:46 +00:00
#### `touchBarButton.label`
2017-03-04 05:14:41 +00:00
A `String` representing the button's current text. Changing this value immediately updates the button
2017-03-03 17:54:46 +00:00
in the touch bar.
#### `touchBarButton.backgroundColor`
2017-03-04 05:14:41 +00:00
A `String` hex code representing the button's current background color. Changing this value immediately updates
2017-03-03 17:54:46 +00:00
the button in the touch bar.
#### `touchBarButton.icon`
2017-03-04 05:14:41 +00:00
A `NativeImage` representing the button's current icon. Changing this value immediately updates the button
2017-03-03 17:54:46 +00:00
in the touch bar.
2019-11-05 23:56:36 +00:00
2020-07-16 18:37:38 +00:00
#### `touchBarButton.iconPosition`
A `String` - Can be `left` , `right` or `overlay` . Defaults to `overlay` .
2019-11-05 23:56:36 +00:00
#### `touchBarButton.enabled`
A `Boolean` representing whether the button is in an enabled state.