The Wayback Machine - http://web.archive.org/web/20200906092337/https://github.com/angular/components/issues/20374
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

bug(Mat Tabs): focusChange event does not fire when selecting first tab #20374

Open
workcomped opened this issue Aug 20, 2020 · 1 comment · May be fixed by #20384
Open

bug(Mat Tabs): focusChange event does not fire when selecting first tab #20374

workcomped opened this issue Aug 20, 2020 · 1 comment · May be fixed by #20384

Comments

@workcomped
Copy link

@workcomped workcomped commented Aug 20, 2020

Reproduction

https://stackblitz.com/edit/angular-yrahxe?file=src%2Fapp%2Ftab-group-basic-example.html

Steps to reproduce:

  1. Create a MatTabGroup with more than one tab
  2. Set selectedIndex input on MatTabGroup to any valid index above 0
  3. bind to focusChange event and attempt to work with this event
  4. Select first tab

Expected Behavior

focusChange event should fire when a tab is changed regardless of initially selected tab (index) as a focus change occurred.

Actual Behavior

focusChange event does not fire if first tab is selected as internally it seems to assume the focus is on the first tab. For example, start on selectedIndex = 1 and clicking second tab will fire the event.

Potential Cause & Fix

It seems that in paginated-tab-header.ts, on initialization the initially active item is always 0. Since we should have access to the selectedIndex by this point, setting the following may address this problem.

this._keyManager.updateActiveItem(this._selectedIndex);

Environment

  • Angular: 10.0.0
  • CDK/Material: 10.0.0
  • Browser(s): Chrome
  • Operating System Windows
@workcomped workcomped changed the title bug(Mat Tabs): focusChange event does not fire when selecting first tab if initial selectedIndex is not 0 bug(Mat Tabs): focusChange event does not fire when selecting first tab Aug 20, 2020
@jelbourn
Copy link
Member

@jelbourn jelbourn commented Aug 20, 2020

Confirmed that this is happening. I think this should be relatively simple to fix.

@crisbeto crisbeto self-assigned this Aug 21, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 21, 2020
We were always defaulting the `focusIndex` to 0 on init, rather than taking the index of the selected tab. We actually had tests for this behavior, but they were all testing against 0 so we never caught the issue.

Fixes angular#20374.
@crisbeto crisbeto added the has pr label Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.