Skip to content

Commit 5775e9c

Browse files
abjerneriOvergaard
authored andcommitted
Added fix for <umb-button-group /> label issues
1 parent fbaa344 commit 5775e9c

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbuttongroup.directive.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Use this directive to render a button with a dropdown of alternative actions.
9393

9494
function ButtonGroupDirective() {
9595

96-
function controller($scope) {
96+
function controller($scope, localizationService) {
9797
$scope.toggleStyle = null;
9898
$scope.blockElement = false;
9999

@@ -121,6 +121,31 @@ Use this directive to render a button with a dropdown of alternative actions.
121121
}
122122
}
123123
}
124+
125+
// As the <localize /> directive doesn't support Angular expressions as fallback, we instead listen for changes
126+
// to the label key of the default button, and if detected, we update the button label with the localized value
127+
// received from the localization service
128+
$scope.$watch("defaultButton.labelKey", function () {
129+
if (!$scope.defaultButton.labelKey) return;
130+
localizationService.localize($scope.defaultButton.labelKey).then(value => {
131+
if (value && value.indexOf("[") === 0) return;
132+
$scope.defaultButton.label = value;
133+
});
134+
});
135+
136+
// In a similar way, we must listen for changes to the sub buttons (or their label keys), and if detected, update
137+
// the label with the localized value received from the localization service
138+
$scope.$watch("defaultButton.subButtons", function () {
139+
if (!Array.isArray($scope.subButtons)) return;
140+
$scope.subButtons.forEach(function (sub) {
141+
if (!sub.labelKey) return;
142+
localizationService.localize(sub.labelKey).then(value => {
143+
if (value && value.indexOf("[") === 0) return;
144+
sub.label = value;
145+
});
146+
});
147+
}, true);
148+
124149
}
125150

126151
function link(scope) {

src/Umbraco.Web.UI.Client/src/views/components/buttons/umb-button-group.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
href-target="{{defaultButton.hrefTarget}}"
99
button-style="{{buttonStyle}}"
1010
state="state"
11-
label="{{defaultButton.labelKey}}"
11+
label="{{defaultButton.label}}"
1212
label-key="{{defaultButton.labelKey}}"
1313
shortcut="{{defaultButton.hotKey}}"
1414
shortcut-when-hidden="{{defaultButton.hotKeyWhenHidden}}"
@@ -29,7 +29,7 @@
2929
ng-disabled="disabled">
3030
<span class="caret">
3131
<span class="sr-only">
32-
<localize key="{{labelKey}}">{{label}}</localize>
32+
{{defaultButton.label}}
3333
</span>
3434
</span>
3535
</button>
@@ -48,8 +48,7 @@
4848
hotkey="{{subButton.hotKey}}"
4949
hotkey-when-hidden="{{subButton.hotKeyWhenHidden}}"
5050
ng-disabled="disabled">
51-
<localize ng-if="subButton.labelKey" key="{{subButton.labelKey}}">{{subButton.labelKey}}</localize>
52-
<span ng-if="subButton.label">{{subButton.label}}</span>
51+
<span>{{subButton.label}}</span>
5352
<span ng-if="subButton.addEllipsis === 'true'">...</span>
5453
</button>
5554
</umb-dropdown-item>

0 commit comments

Comments
 (0)