Skip to content

Cdk listbox dev app #20010

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

Merged
merged 24 commits into from
Jul 21, 2020
Merged

Cdk listbox dev app #20010

merged 24 commits into from
Jul 21, 2020

Conversation

nielsr98
Copy link
Contributor

@nielsr98 nielsr98 commented Jul 16, 2020

Made an example for listbox in the dev-app and added selection of options via arrow key navigation while pressing shift.

@nielsr98 nielsr98 requested a review from jelbourn July 16, 2020 15:43
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 16, 2020
@nielsr98 nielsr98 force-pushed the cdk-listbox-dev-app branch from 087865d to 71d9806 Compare July 16, 2020 17:28
@nielsr98 nielsr98 requested a review from scriby July 16, 2020 17:29
@nielsr98 nielsr98 marked this pull request as ready for review July 16, 2020 17:32
@nielsr98 nielsr98 requested a review from a team as a code owner July 16, 2020 17:38
@nielsr98 nielsr98 added the target: minor This PR is targeted for the next minor release label Jul 16, 2020
it('should focus and toggle the next item when pressing SHIFT + DOWN_ARROW', () => {
let selectedOptions = optionInstances.filter(option => option.selected);
const downKeyEvent = createKeyboardEvent('keydown', DOWN_ARROW);
Object.defineProperty(downKeyEvent, 'shiftKey', {get: () => true});
Copy link
Member

Choose a reason for hiding this comment

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

You should pass the modifiers directly to createKeyboardEvent (so we avoid the defineProperty call here).

'[attr.aria-activedescendant]': '_getAriaActiveDescendant()'
}
})
export class CdkListbox implements AfterContentInit, OnDestroy, OnInit {

_listKeyManager: ActiveDescendantKeyManager<CdkOption>;
_selectionModel: SelectionModel<CdkOption>;
tabIndex = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be prefixed with an underscore? (similarly to how we do it within the selection list)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah probably to stay consistent.

@@ -0,0 +1,10 @@
<ul cdkListbox class="example-listbox" [multiple]="multiSelectable" [useActiveDescendant]="activeDescendant">
<li class="example-option" cdkOption>Apple</li>
Copy link
Member

Choose a reason for hiding this comment

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

Is this class a noop right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes I forgot to remove it after I changed the way I did the styling.

styleUrls: ['cdk-listbox-demo.css'],
})
export class CdkListboxDemo {
multiSelectable = false;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This file should use 2 spaces for indentation.

We should set up a formatter at some point again: #19879

padding: 0;
}

.cdk-option-selected {
Copy link
Member

Choose a reason for hiding this comment

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

Could you change these styles to only target css classes prefixed with demo-? It makes debugging the dev-app easier if you can know immediately where the styles are coming from


/** Will select an option if shift was pressed while navigating to the option */
const isArrow = (keyCode === UP_ARROW || keyCode === DOWN_ARROW);
if (isArrow && event.shiftKey && previousActiveIndex !== this._listKeyManager.activeItemIndex) {
Copy link
Member

Choose a reason for hiding this comment

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

What's the thinking behind toggling options based on arrow keys with shift rather than requiring a separate space/enter keypress? Was this from the aria authoring practices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it would work with a separate space/enter keypress. In the authoring practices it says that selection via SHIFT + arrow key is an optional way to do selection.

Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM for dev-app and build file changes. I'll leave the listbox shift selection change to others (looks reasonable to me though)

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed target: minor This PR is targeted for the next minor release labels Jul 21, 2020
@wagnermaciel wagnermaciel merged commit add6ad1 into angular:master Jul 21, 2020
wagnermaciel pushed a commit that referenced this pull request Jul 21, 2020
* build: Added required files to listbox directory.

* build: added listbox option directive and renamed listbox directive files.

* build: Added required files to listbox directory.

* build: added listbox option directive and renamed listbox directive files.

* build: Added required files to listbox directory.

* build: added listbox option directive and renamed listbox directive files.

* build: Added required files to listbox directory.

* build: added listbox option directive and renamed listbox directive files.

* feat(listbox): added support for non-multiple listbox and aria activedescendant.

* fix(listbox): formatted BUILD.bazel.

* feat(dev-app/listbox): added cdk listbox example to the dev-app.

* feat(listbox): added shift key selection.

* test(listbox): added test for selection via shift key.

* fix(listbox): formatted dev app build file.

* fix(listbox): added codeowners for dev-app listbox example.

* fix(listbox): removed width css property.

* fix(listbox): removed private properties from host bindings to fix view engine bugs.

* nit(listbox): changed double quote to single quote.

* refactor(listbox): fixed some styling errors and added modifier key to createKeyboardEvent.

* nit(listbox): changed spacing.

* nit(listbox): spacing.:

* nit(listbox): removed extra blank line.

* refactor(listbox): changed test to have a stronger check on selected.

* refactor(listbox): changed css classes to use demo- prefix.

(cherry picked from commit add6ad1)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants