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

feat(rating): add keyboard support #1015

Closed
wants to merge 1 commit into from

Conversation

maxokorokov
Copy link
Member

@maxokorokov maxokorokov commented Nov 7, 2016

Adds rating support for the keyboard as follows:

  • arrow left, arrow down, page down → rate--
  • arrow up, arrow right, page up → rate++
  • home → rate = 0
  • end → rate = max

Mostly based on https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_slider_role

@@ -28,6 +40,7 @@ export interface StarTemplateContext {
@Component({
selector: 'ngb-rating',
changeDetection: ChangeDetectionStrategy.OnPush,
host: {'(keydown)': 'handleKeyDown($event)'},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if should be

  • keyup - only increments by 1 once you release the key
  • keydown - increments continuously by 1 while you hold the key

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel keyup makes more sense. I feel for a rating, I would want to press the button x amount of times for the rating I'm giving.

Holding down seems like it would be harder to select the exact number and would cause more mistakes than precise selections.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm still uncertain about this one, but the wai-aria slider demo and bootstrap js plugin use keydown apparently.

Plus from what I understand it's quite common to have this behaviour for navigation keys, so I'll leave it as is for now.


const createTestComponent = (html: string) =>
createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;

enum Key {
PageUp = 33,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should extract this whole enum somewhere (util?) as we start repeating it in few places now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've thought of that too, will open a separate pr for this one

@maxokorokov
Copy link
Member Author

Amended. Removed PgUp and PgDown as they don't make much sense for the rating case

More links with examples:

@maxokorokov
Copy link
Member Author

no idea why it's failing again with some popover.ts issues

@pkozlowski-opensource
Copy link
Member

no idea why it's failing again with some popover.ts issues

No idea either, we need to update clang-format version. But for this we need to merge all the in-flight PRs :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants