Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use angular aria for aria-expanded?

I searched on the Internet and the Angular Aria documentation - it didn't mention about aria-expanded or aria-selected?

Is there a way of implementing this?

<a href ng-aria={'expanded': selected} & ng-aria={'selected': selected}></a>

which will make:

<a href aria-expanded="true" aria-selected="true"></a>

Thanks.

like image 999
user3684783 Avatar asked Jan 05 '16 10:01

user3684783


2 Answers

I used ng-bootstrap to do it. For example:

HTML

<p>
  <button type="button" class="btn btn-outline-primary" (click)="isCollapsed = !isCollapsed"
          [attr.aria-expanded]="!isCollapsed" aria-controls="collapseExample">
    Toggle
  </button>
</p>
<div id="collapseExample" [ngbCollapse]="isCollapsed">
  <div class="card">
    <div class="card-body">
      You can collapse this card by clicking Toggle
    </div>
  </div>
</div>

TYPESCRIPT

import { Component } from '@angular/core';

@Component({
  selector: 'ngbd-collapse-basic',
  templateUrl: './collapse-basic.html'
})
export class NgbdCollapseBasic {
  public isCollapsed = false;
}

Source: https://ng-bootstrap.github.io/#/components/collapse/examples

like image 176
chiconese Avatar answered Dec 16 '22 20:12

chiconese


No need for a directive to set aria-expanded. Just use an expression:

<a href="#" ng-init="selected=false" aria-expanded="{{selected}}" aria-selected="{{selected}}" ng-click="selected=!selected">link</a>

<p ng-show="selected">content<p>
like image 24
neonguru Avatar answered Dec 16 '22 19:12

neonguru