Skip to content

fix(cdk-experimental/listbox): initial listbox focus state #30764

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wagnermaciel
Copy link
Contributor

  • The first option to receive focus in a listbox should be either the first selected option or the first option in the list if no option is selected.

@wagnermaciel wagnermaciel added the target: major This PR is targeted for the next major release label Apr 1, 2025
* The first option to receive focus in a listbox should be either the
  first selected option or the first option in the list if no option
  is selected.
@wagnermaciel wagnermaciel marked this pull request as ready for review April 10, 2025 19:48
@wagnermaciel wagnermaciel requested a review from a team as a code owner April 10, 2025 19:48
@wagnermaciel wagnermaciel requested review from crisbeto and mmalerba and removed request for a team April 10, 2025 19:48
constructor() {
effect(() => {
if (this._isViewInitialized() && !this._touched()) {
const index = this.items().findIndex(i => this.value().includes(i.value()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels weird to have these signal-reads knowing that it causes this effect to be run a lot. I guess it doesn't matter because of the initial conditional check, so its a fast function. But I wish there was a way for Angular to know this should really only be run based on the two conditional signals

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree. Having to have a signal for isViewInitialized feels very janky. This was the only way I could get around Angular throwing an error because a required signal hasn't been set.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the this.items(), this.value(), i.value() - these will all trigger the effect right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes but those are needed to trigger the effect in order to figure out the correct start index. The effect should rerun any time those signals change until the listbox is touched (focused for the first time)

Copy link
Contributor

Choose a reason for hiding this comment

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

But I wish there was a way for Angular to know this should really only be run based on the two conditional signals

I think you can wrap the rest of the reads in untracked(() => ...) to indicate that (though it sounds like maybe you do need it to react to all of them here, just wanted to give an fyi that the feature exists)

@wagnermaciel wagnermaciel added the action: merge The PR is ready for merge by the caretaker label Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants