Enhancing angular component with aria-label attribute

I have created a star rating component and I want to include a description for screen readers like JAWS to read when tabbed. Currently, when using JAWS, there is no description being read (it should ideally read the rating for the user). What is the process for adding aria-labels to angular components?

star-rating.component.ts

<div [attr.aria-label]="'the rating is' + {{rating}} + 'out of' + {{starAmount}} + 'stars'">
    <app-star 
    *ngFor="let star of stars; let i = index"
    [rating]="rating"
    [starAmount]="starAmount">
    </app-star>
<div>

star-rating.component.ts

import { Component, Input } from "@angular/core";

@Component({
  selector: "app-star-rating",
  templateUrl: "./star-rating.component.html",
  styleUrls: ["./star-rating.component.css"]
})
export class StarRatingComponent {
  @Input() starAmount;
  @Input() rating;
  total;
  Arr = Array;


}

Answer №1

Your aria-label attribute in the div seems to be causing issues. Since you are already using an Angular input ([attr.aria-label]), the value is Javascript and does not require the use of {{ }} within it.

Try using the following line instead:


[attr.aria-label]="'the rating is ' + rating + ' out of ' + starAmount + ' stars'"

It's surprising that you did not receive any errors from Angular initially.

Answer №2

When using both NVDA and JAWS screen readers, the content below is read in a semantic way, depending on certain conditional values:

[attr.aria-label]="((client.issbInstalled)? 'Secure Browser is installed' :
 'Secure Browser is not installed ') + 'with' + index + client?.clientHostName"

ALTERNATIVELY

[attr.aria-label]="{
 true:'Secure Browser is installed with' + client?.clientHostName, 
 false: 'Secure Browser is not installed with' + client?.clientHostName
}[client.issbInstalled]"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am looking to develop a unique event that can be triggered by any component and listened to by any other component within my Angular 7 application

Looking to create a unique event that can be triggered from any component and listened to by any other component within my Angular 7 app. Imagine having one component with a button that, when clicked, triggers the custom event along with some data. Then, ...

What causes the index to display [object Object] rather than an integer in React?

It has been a long time since I last worked with React, and now I'm facing an issue. Whenever I use console.log to display the index within the map function, my console output looks like this: https://i.stack.imgur.com/VbGmE.png However, the result ...

Having troubles with angular due to doodle throwing errors?

https://codepen.io/tuckermassad/pen/rPYNLq I took the CSS doodle code from the above link and incorporated it into my angular component: <section class="main"> <css-doodle grid="5"> :doodle { @grid: 10 / 100%; } ...

Steps for setting up Angular 5 on your system

My current project requires Angular 5, but with the recent release of Angular 7, I'm unsure how to set up Angular 5 on my computer. I had transitioned from Angular 6 a few months ago. Do I need to uninstall the latest version to work with Angular 5? ...

When using the Angular Material table with selection enabled, the master toggle functionality should always deselect the

I made modifications to the original Angular Material Table example - Stackblitz. In my version, when some rows are selected and the master toggle is clicked, all selected rows should be deselected (similar to Gmail behavior). The functionality works, but ...

Angular's import and export functions are essential features that allow modules

Currently, I am working on a complex Angular project that consists of multiple components. One specific scenario involves an exported `const` object in a .ts file which is then imported into two separate components. export const topology = { "topolo ...

Incorporate my personalized icons into the button design of ionic 2 actionSheet

I'm struggling to figure out how to incorporate my personal icon into the actionSheet feature of ionic 2/3. presentActionSheet() { let actionSheet = this.actionSheetCtrl.create({ title: 'Mode', buttons: [ { ...

Utilizing the adapter design pattern in Angular with TypeScript for enhancing a reactive form implementation

I've been struggling to understand how to implement the adapter pattern in Angular6. Despite reading numerous articles and tutorials, I still can't quite grasp the concept. Could someone provide some insights on this topic? Essentially, I have a ...

Utilizing the MapToIterable Angular Pipe with TypeScript

Exploring the implementation of a pipe in Angular. Discovered that ngFor doesn't work with maps, prompting further research to find a solution. It seems that future features may address this issue, but for now, utilizing a mapToIterable pipe is the re ...

Creating a Protected Deployment Environment on AWS for Angular and Spring Boot Applications

Recently, I attempted to deploy a backend Spring Boot application and an Angular front end application on AWS. After successfully pushing my Docker image to ECS, I managed to run multiple services behind application load balancers. Specifically, I set up t ...

Arrangement of items in Angular 2 array

Received a JSON response structured like this JSON response "Terms": [ { "Help": "Terms", "EventType": "Success", "Srno": 1, "Heading": "Discount Condition", "T ...

Checking for Object Equality in TypeScript

I'm working on a TypeScript vector library and encountered my first failed test. The issue revolves around object equality in TypeScript/JavaScript, and despite searching through TypeScript's official documentation (http://www.typescriptlang.org ...

Is it possible that the installation issue with 'File' from ionic-native is due to dependencies?

As a newcomer to Ionic2, I'm facing some beginner obstacles. Despite my extensive search efforts, I haven't been able to find any examples related to my issue. My current goal is to write a file to a specific directory on the device using Ionic2 ...

An issue occurred during the compilation of an Angular6 project

I am embarking on my first Angular project and may not grasp every detail perfectly. In my search for guidance, I came across the command "ng build --prod" on Google and decided to give it a try. Everything seemed to be going smoothly at first until an err ...

Receiving a CORS issue while integrating Django as the backend for an Ionic application

I have integrated Django Rest Framework as a backend for my Ionic application. The API setup using JWT is successfully tested with Postman. However, when attempting to make an API call from the Ionic app, I encounter the following errors: Error 1 Cross-Or ...

Setting up NextJs in Visual Studio Code with Yarn

When I used yarn create next-app --typescript to set up a TypeScript Next.js application with Yarn, everything seemed to be working fine with the command yarn run dev. However, Visual Studio Code was not recognizing any of the yarn packages that were added ...

Understanding authorization and user roles within an Angular 2 application utilizing Microsoft Graph

As a newcomer, I am in the process of developing a CVThèque application using angular 2 and .net core. For authentication purposes, I have integrated Microsoft Graph and adal successfully. However, I am unsure how to set up permissions and group roles for ...

Customizing Components in Angular 2/4 by Overriding Them from a Different Module

Currently, I am utilizing Angular 4.3 and TypeScript 2.2 for my project. My goal is to develop multiple websites by reusing the same codebase. Although most of the websites will have similar structures, some may require different logic or templates. My p ...

Having trouble with react-i18next not working properly in my React Native application

I recently initiated a new react-native project, but I seem to be encountering an issue with my react-i18next translations. Despite having the keys correctly set up, I am unable to view the translations. Furthermore, I have noticed that my components are ...

The default selected item in Material Select does not function properly on the second attempt

Is there a way to reset an Angular Material Select Component to its default value after manually changing it on the UI screen? It seems to work fine during initialization but not after manual changes. I am attempting to create a button that will revert th ...