From 1cffac4434bc8ea61935471634092a88f95c38ee Mon Sep 17 00:00:00 2001 From: Anna Dingler Date: Wed, 1 Mar 2023 16:56:38 -0800 Subject: [PATCH] Add role property to actions - JS --- samples/v1.6/Elements/Action.Role.json | 83 +++++++++++++++++++ .../nodejs/adaptivecards/src/card-elements.ts | 27 +++++- source/nodejs/adaptivecards/src/enums.ts | 8 ++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 samples/v1.6/Elements/Action.Role.json diff --git a/samples/v1.6/Elements/Action.Role.json b/samples/v1.6/Elements/Action.Role.json new file mode 100644 index 0000000000..1d6c5cb5b7 --- /dev/null +++ b/samples/v1.6/Elements/Action.Role.json @@ -0,0 +1,83 @@ +{ + "type": "AdaptiveCard", + "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", + "version": "1.6", + "body": [ + { + "type": "TextBlock", + "text": "The actions below should use the enum role values", + "wrap": true + }, + { + "type": "ActionSet", + "actions": [ + { + "type": "Action.OpenUrl", + "title": "Action.OpenUrl", + "role": "button" + }, + { + "type": "Action.Submit", + "title": "Action.Submit", + "role": "tab" + }, + { + "type": "Action.ShowCard", + "title": "Action.ShowCard", + "card": { + "type": "AdaptiveCard" + }, + "role": "menu" + }, + { + "type": "Action.ToggleVisibility", + "title": "Action.ToggleVisibility", + "role": "menuItem" + }, + { + "type": "Action.Execute", + "title": "Action.Execute", + "role": "link" + } + ] + }, + { + "type": "TextBlock", + "text": "The actions below have invalid role values and should default to link and button", + "wrap": true + }, + { + "type": "ActionSet", + "actions": [ + { + "type": "Action.OpenUrl", + "title": "Action.OpenUrl", + "role": "invalidrole" + }, + { + "type": "Action.Submit", + "title": "Action.Submit", + "role": "invalidrole" + } + ] + }, + { + "type": "TextBlock", + "text": "The actions below do not have role values and should be link and button", + "wrap": true + }, + { + "type": "ActionSet", + "actions": [ + { + "type": "Action.OpenUrl", + "title": "Action.OpenUrl" + }, + { + "type": "Action.Submit", + "title": "Action.Submit" + } + ] + } + ] +} diff --git a/source/nodejs/adaptivecards/src/card-elements.ts b/source/nodejs/adaptivecards/src/card-elements.ts index 9c7310c87c..dfc7af3b96 100644 --- a/source/nodejs/adaptivecards/src/card-elements.ts +++ b/source/nodejs/adaptivecards/src/card-elements.ts @@ -5393,6 +5393,7 @@ export abstract class Action extends CardObject { ); static readonly tooltipProperty = new StringProperty(Versions.v1_5, "tooltip"); static readonly isEnabledProperty = new BoolProperty(Versions.v1_5, "isEnabled", true); + static readonly roleProperty = new EnumProperty(Versions.v1_6, "role", Enums.ActionRole); @property(Action.titleProperty) title?: string; @@ -5411,6 +5412,9 @@ export abstract class Action extends CardObject { @property(Action.isEnabledProperty) isEnabled: boolean; + + @property(Action.roleProperty) + role?: Enums.ActionRole; //#endregion @@ -5589,7 +5593,25 @@ export abstract class Action extends CardObject { } getAriaRole(): string { - return "button"; + let ariaRole = this.getAriaRoleFromEnum(); + return ariaRole ?? "button"; + } + + getAriaRoleFromEnum(): string | undefined { + switch (this.role) { + case Enums.ActionRole.Button: + return "button"; + case Enums.ActionRole.Link: + return "link"; + case Enums.ActionRole.Menu: + return "menu"; + case Enums.ActionRole.MenuItem: + return "menuitem"; + case Enums.ActionRole.Tab: + return "tab"; + default: + return undefined; + } } setupElementForAccessibility(element: HTMLElement, promoteTooltipToLabel: boolean = false) { @@ -6004,7 +6026,8 @@ export class OpenUrlAction extends Action { } getAriaRole(): string { - return "link"; + let ariaRole = this.getAriaRoleFromEnum(); + return ariaRole ?? "link"; } internalValidateProperties(context: ValidationResults) { diff --git a/source/nodejs/adaptivecards/src/enums.ts b/source/nodejs/adaptivecards/src/enums.ts index 036d2ec3d5..693e54a667 100644 --- a/source/nodejs/adaptivecards/src/enums.ts +++ b/source/nodejs/adaptivecards/src/enums.ts @@ -223,3 +223,11 @@ export enum CarouselInteractionEvent { Pagination, Autoplay } + +export enum ActionRole { + Button, + Link, + Tab, + Menu, + MenuItem +}