Skip to content

Commit 058f901

Browse files
authored
V15/feature/toggle property editor UI (#18171)
* update the setting for the toggle satet * update the setting for the toggle satet * adds a fallback label if no ariaLabel is set in the manifest, using toggleFor
1 parent f1cdf50 commit 058f901

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

src/Umbraco.Web.UI.Client/src/assets/lang/en-us.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ export default {
822822
error: 'Error',
823823
field: 'Field',
824824
fieldFor: 'Field for %0%',
825+
toggleFor: 'Toggle for %0%',
825826
findDocument: 'Find',
826827
first: 'First',
827828
focalPoint: 'Focal point',

src/Umbraco.Web.UI.Client/src/assets/lang/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ export default {
819819
error: 'Error',
820820
field: 'Field',
821821
fieldFor: 'Field for %0%',
822+
toggleFor: 'Toggle for %0%',
822823
findDocument: 'Find',
823824
first: 'First',
824825
focalPoint: 'Focal point',

src/Umbraco.Web.UI.Client/src/packages/core/components/input-toggle/input-toggle.element.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class UmbInputToggleElement extends UUIFormControlMixin(UmbLitElement, ''
2626
@property({ type: String })
2727
labelOff?: string;
2828

29+
@property({ type: String, attribute: 'aria-label' })
30+
override ariaLabel: string | null = null;
31+
2932
/**
3033
* Sets the input to readonly mode, meaning value cannot be changed but still able to read and select its content.
3134
* @type {boolean}
@@ -42,6 +45,8 @@ export class UmbInputToggleElement extends UUIFormControlMixin(UmbLitElement, ''
4245
return undefined;
4346
}
4447

48+
// test
49+
4550
override connectedCallback(): void {
4651
super.connectedCallback();
4752
this.#updateLabel();
@@ -54,15 +59,15 @@ export class UmbInputToggleElement extends UUIFormControlMixin(UmbLitElement, ''
5459
}
5560

5661
#updateLabel() {
57-
this._currentLabel = this.showLabels ? (this.checked ? this.labelOn : this.labelOff) : '';
62+
this._currentLabel = this.showLabels ? (this.checked ? this.labelOn : this.labelOff) : '';
5863
}
5964

6065
override render() {
6166
return html`<uui-toggle
6267
.checked=${this.#checked}
63-
.label=${this._currentLabel}
68+
.label="${this.ariaLabel}"
6469
@change=${this.#onChange}
65-
?readonly=${this.readonly}></uui-toggle>`;
70+
?readonly=${this.readonly}><span>${this._currentLabel}</span> </uui-toggle>`;
6671
}
6772

6873
static override styles = [

src/Umbraco.Web.UI.Client/src/packages/property-editors/toggle/manifests.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,43 @@ export const manifests: Array<UmbExtensionManifest> = [
1616
properties: [
1717
{
1818
alias: 'default',
19-
label: 'Initial State',
20-
description:
21-
'The initial state for the toggle, when it is displayed for the first time in the backoffice, eg. for a new content item.',
19+
label: 'Preset value',
2220
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Toggle',
21+
config: [
22+
23+
{
24+
alias: "ariaLabel",
25+
value: 'toggle for the initial state of this data type'
26+
}
27+
]
2328
},
2429
{
2530
alias: 'showLabels',
26-
label: 'Show toggle labels',
27-
description: 'Show labels next to toggle button.',
31+
label: 'Show on/off labels',
2832
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Toggle',
33+
config: [
34+
35+
{
36+
alias: "ariaLabel",
37+
value: 'toggle for weather if label should be displayed'
38+
}
39+
]
2940
},
3041
{
3142
alias: 'labelOn',
3243
label: 'Label On',
33-
description: 'Label text when enabled.',
44+
description: 'Displays text when enabled.',
3445
propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
3546
},
3647
{
3748
alias: 'labelOff',
3849
label: 'Label Off',
39-
description: 'Label text when disabled.',
50+
description: 'Displays text when disabled.',
51+
propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
52+
},
53+
{
54+
alias: 'ariaLabel',
55+
label: 'Screen Reader Label',
4056
propertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
4157
},
4258
],

src/Umbraco.Web.UI.Client/src/packages/property-editors/toggle/property-editor-ui-toggle.element.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,30 @@ export class UmbPropertyEditorUIToggleElement extends UmbLitElement implements U
2424
@property({ type: Boolean, reflect: true })
2525
readonly = false;
2626

27+
@state()
28+
_ariaLabel?: string;
29+
2730
@state()
2831
_labelOff?: string;
2932

3033
@state()
3134
_labelOn?: string;
3235

36+
@property({ type: String })
37+
name?: string;
38+
3339
@state()
3440
_showLabels = false;
3541

42+
3643
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
3744
if (!config) return;
3845
this.value ??= config.getValueByAlias('default') ?? false;
46+
3947
this._labelOff = config.getValueByAlias('labelOff');
4048
this._labelOn = config.getValueByAlias('labelOn');
4149
this._showLabels = Boolean(config.getValueByAlias('showLabels'));
50+
this._ariaLabel = config.getValueByAlias('ariaLabel');
4251
}
4352

4453
#onChange(event: CustomEvent & { target: UmbInputToggleElement }) {
@@ -49,7 +58,8 @@ export class UmbPropertyEditorUIToggleElement extends UmbLitElement implements U
4958
override render() {
5059
return html`
5160
<umb-input-toggle
52-
.labelOn=${this._labelOn}
61+
62+
.ariaLabel=${this._ariaLabel ? this.localize.string(this._ariaLabel) : this.localize.term('general_toggleFor', [this.name])}
5363
.labelOff=${this._labelOff}
5464
?checked=${this.value}
5565
?showLabels=${this._showLabels}

0 commit comments

Comments
 (0)