Skip to content

Commit

Permalink
fix(dropdown): use button elements instead of links
Browse files Browse the repository at this point in the history
This fixes accessibility and cursor display issues.
Part of #142

closes #490
  • Loading branch information
pkozlowski-opensource authored and icfantv committed Jul 29, 2016
1 parent 8402695 commit aeeee01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div ngbDropdown>
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<a class="dropdown-item">Action - 1</a>
<a class="dropdown-item">Another Action</a>
<a class="dropdown-item">Something else is here</a>
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
</div>
</div>
5 changes: 2 additions & 3 deletions src/typeahead/test-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ function normalizeText(txt: string): string {
}

export function getWindowLinks(element: DebugElement): DebugElement[] {
return Array.from(element.queryAll(By.css('a')));
return Array.from(element.queryAll(By.css('button.dropdown-item')));
}

export function expectResults(nativeEl: HTMLElement, resultsDef: string[]): void {
const pages = nativeEl.querySelectorAll('a');
const pages = nativeEl.querySelectorAll('button.dropdown-item');

expect(pages.length).toEqual(resultsDef.length);

for (let i = 0; i < resultsDef.length; i++) {
let resultDef = resultsDef[i];
let classIndicator = resultDef.charAt(0);

expect(pages[i]).toHaveCssClass('dropdown-item');
if (classIndicator === '+') {
expect(pages[i]).toHaveCssClass('active');
expect(normalizeText(pages[i].textContent)).toEqual(resultDef.substr(1));
Expand Down
4 changes: 2 additions & 2 deletions src/typeahead/typeahead-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export class ResultTplCtx {
<ngb-highlight [result]="formatter(result)" [term]="term"></ngb-highlight>
</template>
<template ngFor [ngForOf]="results" let-result let-idx="index">
<a class="dropdown-item" [class.active]="idx === _activeIdx"
<button class="dropdown-item" [class.active]="idx === _activeIdx"
(mouseenter)="markActive(idx)"
(click)="select(result)">
<template [ngTemplateOutlet]="resultTemplate || rt" [ngOutletContext]="_prepareTplCtx(result)"></template>
</a>
</button>
</template>
`,
directives: [NgbHighlight]
Expand Down

0 comments on commit aeeee01

Please sign in to comment.