Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] Add role property to actions #8336

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions samples/v1.6/Elements/Action.Role.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
27 changes: 25 additions & 2 deletions source/nodejs/adaptivecards/src/card-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -5411,6 +5412,9 @@ export abstract class Action extends CardObject {

@property(Action.isEnabledProperty)
isEnabled: boolean;

@property(Action.roleProperty)
role?: Enums.ActionRole;

//#endregion

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -6004,7 +6026,8 @@ export class OpenUrlAction extends Action {
}

getAriaRole(): string {
return "link";
let ariaRole = this.getAriaRoleFromEnum();
return ariaRole ?? "link";
}

internalValidateProperties(context: ValidationResults) {
Expand Down
8 changes: 8 additions & 0 deletions source/nodejs/adaptivecards/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,11 @@ export enum CarouselInteractionEvent {
Pagination,
Autoplay
}

export enum ActionRole {
Button,
Link,
Tab,
Menu,
MenuItem
}