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
Combobox open actions #20306
Conversation
closePanel(data?: T) { | ||
this.valueUpdated.next(data); | ||
} | ||
|
||
focusContent() { | ||
document.getElementById(this.contentId)?.focus(); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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']) |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
|
||
_handleInteractions(interaction: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_handleInteractions(interaction: string) { | |
_handleInteractions(interaction: OpenAction) { |
@@ -103,6 +112,45 @@ export class CdkCombobox<T = unknown> implements OnDestroy, AfterContentInit { | |||
this.panelValueChanged.complete(); | |||
} | |||
|
|||
keydown(event: KeyboardEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…impler for this PR.
…tespace separated strings as input.
… value to combobox.
…fixed the setTextContent function.
…ode, condense click and focus handlers into one.
…panel content with panel.
15dface
to
ddff626
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
New features include: