Skip to content

Commit

Permalink
feat(rating): set cursor on stars of rating component (#411)
Browse files Browse the repository at this point in the history
The cursor used on the stars of the rating component is a text selection cursor, which doesn't make it clear that they're clickable. The cursor stays the same if the rating component is readonly.
This commit sets a 'pointer' cursor on the stars, and a 'not-allowed' cursor when it's read-only.
  • Loading branch information
jnizet authored and Foxandxss committed Jul 9, 2016
1 parent 32c251e commit bcba259
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/rating/rating.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ describe('ngb-rating', () => {
});
})));

it('should set pointer cursor on stars when not readonly', async(inject([TestComponentBuilder], (tcb) => {
tcb.createAsync(NgbRating).then((fixture) => {
fixture.detectChanges();

const compiled = fixture.nativeElement;

expect(window.getComputedStyle(getStar(compiled, 1)).getPropertyValue('cursor')).toBe('pointer');
});
})));

it('should set not allowed cursor on stars when readonly', async(inject([TestComponentBuilder], (tcb) => {
const html = '<ngb-rating [readonly]="true"></ngb-rating>';
return tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
fixture.detectChanges();

const compiled = fixture.nativeElement;

expect(window.getComputedStyle(getStar(compiled, 1)).getPropertyValue('cursor')).toBe('not-allowed');
});
})));

describe('aria support', () => {
it('contains aria-valuemax with the number of stars', async(inject([TestComponentBuilder], (tcb) => {
const html = '<ngb-rating [max]="max"></ngb-rating>';
Expand Down
3 changes: 2 additions & 1 deletion src/rating/rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {Component, ChangeDetectionStrategy, Input, Output, EventEmitter, OnInit}
<template ngFor let-r [ngForOf]="range" let-index="index">
<span class="sr-only">({{ index < rate ? '*' : ' ' }})</span>
<span (mouseenter)="enter(index + 1)" (click)="update(index + 1)" [title]="r.title"
[attr.aria-valuetext]="r.title">{{ index < rate ? '&#9733;' : '&#9734;' }}</span>
[attr.aria-valuetext]="r.title"
[style.cursor]="readonly ? 'not-allowed' : 'pointer'">{{ index < rate ? '&#9733;' : '&#9734;' }}</span>
</template>
</span>
`
Expand Down

0 comments on commit bcba259

Please sign in to comment.