Skip to content

Commit

Permalink
feat: improve TouchBarButton accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Oct 6, 2019
1 parent 87bd050 commit 2823e1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/api/touch-bar-button.md
Expand Up @@ -8,16 +8,23 @@ Process: [Main](../tutorial/application-architecture.md#main-and-renderer-proces

* `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](native-image.md) | 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.

If you choose to define the `accessibilityLabel`, ensure you have considered macOS [best practices](https://developer.apple.com/documentation/appkit/nsaccessibilitybutton/1524910-accessibilitylabel?language=objc).

### 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
Expand Down
3 changes: 2 additions & 1 deletion lib/browser/api/touch-bar.js
Expand Up @@ -191,8 +191,9 @@ TouchBar.TouchBarButton = class TouchBarButton extends TouchBarItem {
super()
if (config == null) config = {}
this._addImmutableProperty('type', 'button')
const { click, icon, iconPosition, label, backgroundColor } = config
const { click, icon, iconPosition, label, backgroundColor, accessibilityLabel } = config
this._addLiveProperty('label', label)
this._addLiveProperty('accessibilityLabel', accessibilityLabel)
this._addLiveProperty('backgroundColor', backgroundColor)
this._addLiveProperty('icon', icon)
this._addLiveProperty('iconPosition', iconPosition)
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/ui/cocoa/atom_touch_bar.mm
Expand Up @@ -363,6 +363,10 @@ - (void)updateButton:(NSCustomTouchBarItem*)item
button.bezelColor = nil;
}

std::string accessibilityLabel;
settings.Get("accessibilityLabel", &accessibilityLabel);
button.accessibilityLabel = base::SysUTF8ToNSString(accessibilityLabel);

std::string label;
settings.Get("label", &label);
button.title = base::SysUTF8ToNSString(label);
Expand Down

0 comments on commit 2823e1d

Please sign in to comment.