electron/docs/api/touch-bar-button.md
Samuel Attard 81795744cf
fix: ensure the typescript definitions only export correct value types (#28712)
* fix: ensure the typescript definitions only export correct value types

In typescript there are two main types of "types" you can export, value types (class, const) and definition types (type, interface).  The typescript compiler will let anything declared via const or class be used as a value.  Unfortunately we were exporting a bunch of things (see the diff) as class/const when they weren't actually exported values. This lead to typescript being happy but the runtime throwing errors (not something we want).

This change passes "exported-in" context through our docs, to the parser and then to the definitions generator to ensure we only mark things as exported in the ts defs that we actually export.

Fixes #22167

* chore: update typescript-defs

* chore: update typescript-defs

* chore: fix bad typescript in IPC test

* docs: test rendering of new syntax

* chore: update per feedback, use same syntax but with 'this is not exportedd' line
2021-06-15 13:50:31 -07:00

2.1 KiB

Class: TouchBarButton

Create a button in the touch bar for native macOS applications

Process: Main
This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

new TouchBarButton(options)

  • options Object
    • label String (optional) - Button text.
    • accessibilityLabel String (optional) - A short description of the button for use by screenreaders like VoiceOver.
    • backgroundColor String (optional) - Button background color in hex format, i.e #ABCDEF.
    • icon NativeImage | String (optional) - Button icon.
    • iconPosition String (optional) - Can be left, right or overlay. Defaults to overlay.
    • click Function (optional) - Function to call when the button is clicked.
    • enabled Boolean (optional) - Whether the button is in an enabled state. Default is true.

When defining accessibilityLabel, ensure you have considered macOS best practices.

Instance Properties

The following properties are available on instances of TouchBarButton:

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.

touchBarButton.label

A String representing the button's current text. Changing this value immediately updates the button in the touch bar.

touchBarButton.backgroundColor

A String hex code representing the button's current background color. Changing this value immediately updates the button in the touch bar.

touchBarButton.icon

A NativeImage representing the button's current icon. Changing this value immediately updates the button in the touch bar.

touchBarButton.iconPosition

A String - Can be left, right or overlay. Defaults to overlay.

touchBarButton.enabled

A Boolean representing whether the button is in an enabled state.