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

fix(tab): Set initial tabIndex state to -1 (#690) #691

Merged
merged 1 commit into from Feb 23, 2019
Merged

fix(tab): Set initial tabIndex state to -1 (#690) #691

merged 1 commit into from Feb 23, 2019

Conversation

ghost
Copy link

@ghost ghost commented Feb 22, 2019

Sets the initial state for the tabIndex the same way it is set for aria-selected. If a tab is active then the activate method on the foundation will update this state on mount.

@codecov-io
Copy link

Codecov Report

Merging #691 into rc0.11.0 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           rc0.11.0     #691   +/-   ##
=========================================
  Coverage     94.88%   94.88%           
=========================================
  Files            68       68           
  Lines          2853     2853           
  Branches        432      432           
=========================================
  Hits           2707     2707           
  Misses           50       50           
  Partials         96       96
Impacted Files Coverage Δ
packages/tab/index.tsx 98.83% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52eeb52...365b44a. Read the comment docs.

@patrickrodee patrickrodee self-assigned this Feb 22, 2019
});

test('sets the tabIndex to -1 if props.active is false on mount', () => {
const wrapper = shallow(<Tab active={false} />);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we update this to set no active property instead of explicitly setting active={false}? Will the test still pass?

Copy link

Choose a reason for hiding this comment

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

Typically with these props, it wouldn't be hard-coded. It would usually look more like:

<Tab active={this.state.active} />

In that case it is more helpful to have that prop explicitly defined like that. Otherwise removing it would look like:

const props = {};
if (this.state.active) {
  props.active = true;
}
<Tab {...props} />

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, thanks for explaining. My thinking was that removing the active={false} prop tests that a Tab has tab-index=-1 by default without the user providing any active prop. However, that's more a test of Component.defaultProps working than of the change here.

Copy link
Contributor

@patrickrodee patrickrodee left a comment

Choose a reason for hiding this comment

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

LGTM!

});

test('sets the tabIndex to -1 if props.active is false on mount', () => {
const wrapper = shallow(<Tab active={false} />);
Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, thanks for explaining. My thinking was that removing the active={false} prop tests that a Tab has tab-index=-1 by default without the user providing any active prop. However, that's more a test of Component.defaultProps working than of the change here.

@moog16
Copy link

moog16 commented Feb 23, 2019

That totally makes sense...and I had a double take for a second :)

@moog16 moog16 merged commit 84043a3 into material-components:rc0.11.0 Feb 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants