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

Combobox open actions #20306

Merged
merged 33 commits into from Aug 14, 2020
Merged

Conversation

nielsr98
Copy link
Contributor

New features include:

  • Logic to handle multiple different open actions
  • Coercion function for string -> open action
  • Many additional tests

@nielsr98 nielsr98 requested a review from scriby August 13, 2020 21:02
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 13, 2020
closePanel(data?: T) {
this.valueUpdated.next(data);
}

focusContent() {
document.getElementById(this.contentId)?.focus();
Copy link
Member

Choose a reason for hiding this comment

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

I would add a TODO here to use an injected document and a separate TODO to potentially switch this to use focus trapping from cdk/a11y

constructor(readonly _templateRef: TemplateRef<unknown>) {}
constructor(
readonly _templateRef: TemplateRef<unknown>,
readonly _elementRef: ElementRef<HTMLElement>
Copy link
Member

Choose a reason for hiding this comment

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

I think you can drop this elementRef now

@@ -103,6 +109,48 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
this.panelValueChanged.complete();
}

onClick() {
Copy link
Member

Choose a reason for hiding this comment

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

It would probably make sense to make one method like _handleInteraction(action) and then set up the event handlers like '(click)': '_handleInteraction("click")', etc.

}
}

@HostListener('document:click', ['$event'])
Copy link
Member

Choose a reason for hiding this comment

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

Prefer adding this to the host object

host: {
  '(document:click)': '_attemptClose($event)',
}

@@ -188,10 +241,18 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {

private _coerceOpenActionProperty(input: string | OpenAction[]): OpenAction[] {
let actions: OpenAction[] = [];
const viableActions = ['focus', 'click', 'downKey', 'toggle'];
Copy link
Member

Choose a reason for hiding this comment

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

I would change this to a file-level constant

Comment on lines 243 to 257
let actions: OpenAction[] = [];
const viableActions = ['focus', 'click', 'downKey', 'toggle'];

if (typeof input === 'string') {
actions.push(input as OpenAction);
const tokens = input.trim().split(/[ ,]+/);
for (const token of tokens) {
if (viableActions.indexOf(token) === -1) {
throw Error(`${token} is not a supported open action`);
}
actions.push(token as OpenAction);
}
} else {
actions = input;
actions = coerceArray(input);
}
return actions;
Copy link
Member

Choose a reason for hiding this comment

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

let actions = typeof input === 'string' ? input.trim().split(/[ ,]+/) : input;
if (isDevMode() && actions.some(a => allowedOpenActions.indexOf(a) === -1)) {
  throw Error(`${input} is not a support open action for CdkCombobox`);
}
return actions;
  • We'd want to do the sanity check even if the value isn't a string
  • We'd only want to do the sanity check in dev mode
  • I think the else isn't doing anything since it's already an array if it's not a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see this makes sense. The some function helps condense it too.

Copy link

@Matausi29 Matausi29 left a comment

Choose a reason for hiding this comment

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

}
}

_handleInteractions(interaction: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_handleInteractions(interaction: string) {
_handleInteractions(interaction: OpenAction) {

@@ -103,6 +112,45 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit {
this.panelValueChanged.complete();
}

keydown(event: KeyboardEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
keydown(event: KeyboardEvent) {
_keydown(event: KeyboardEvent) {

Should have an underscore since this isn't a public API

'tabIndex': '-1'
}
})
export class DialogContent<V> implements OnInit {
Copy link
Member

Choose a reason for hiding this comment

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

I might make this FakeDialogContent just so it doesn't come up for IDE shortcuts like shift+shift when looking for dialog stuff

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

@nielsr98 nielsr98 added the target: minor This PR is targeted for the next minor release label Aug 14, 2020
@jelbourn jelbourn added action: merge The PR is ready for merge by the caretaker merge safe merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed labels Aug 14, 2020
@andrewseguin andrewseguin merged commit 809f157 into angular:master Aug 14, 2020
@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 Sep 14, 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 merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants