mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: allow TouchBarButton instances to be disabled (#20945)
* feat: allow TouchBarButton instances to be disabled * Update touch-bar-button.md
This commit is contained in:
@@ -14,6 +14,7 @@ Process: [Main](../tutorial/application-architecture.md#main-and-renderer-proces
|
||||
* `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.
|
||||
* `enabled` Boolean (optional) - Whether the button is in an enabled state. Default is `true`.
|
||||
|
||||
When defining `accessibilityLabel`, ensure you have considered macOS [best practices](https://developer.apple.com/documentation/appkit/nsaccessibilitybutton/1524910-accessibilitylabel?language=objc).
|
||||
|
||||
@@ -39,3 +40,7 @@ the button in the touch bar.
|
||||
|
||||
A `NativeImage` representing the button's current icon. Changing this value immediately updates the button
|
||||
in the touch bar.
|
||||
|
||||
#### `touchBarButton.enabled`
|
||||
|
||||
A `Boolean` representing whether the button is in an enabled state.
|
||||
|
||||
@@ -196,6 +196,7 @@ TouchBar.TouchBarButton = class TouchBarButton extends TouchBarItem {
|
||||
this._addLiveProperty('backgroundColor', config.backgroundColor)
|
||||
this._addLiveProperty('icon', config.icon)
|
||||
this._addLiveProperty('iconPosition', config.iconPosition)
|
||||
this._addLiveProperty('enabled', typeof config.enabled !== 'boolean' ? true : config.enabled)
|
||||
if (typeof config.click === 'function') {
|
||||
this._addImmutableProperty('onInteraction', () => {
|
||||
config.click()
|
||||
|
||||
@@ -384,6 +384,10 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||
button.imagePosition = NSImageOverlaps;
|
||||
}
|
||||
}
|
||||
|
||||
bool enabled = true;
|
||||
settings.Get("enabled", &enabled);
|
||||
[button setEnabled:enabled];
|
||||
}
|
||||
|
||||
- (NSTouchBarItem*)makeLabelForID:(NSString*)id
|
||||
|
||||
Reference in New Issue
Block a user