-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 Tabs indicator style when changed via controlled mode #48
Conversation
6dbfc7a
to
431a8a0
Compare
431a8a0
to
0ab43df
Compare
if (newIndex !== prevState.selectedTabIndex) { | ||
const tabElement = findDOMNode(this.refs[`tabs-${newIndex}`]) as HTMLElement; | ||
// need to measure on the next frame in case the Tab children simultaneously change | ||
setTimeout(() => { this.moveIndicator(tabElement); }); |
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.
nit: I think you can omit the { }
in this line
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.
Thanks. Will update.
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.
generally I would only address nits in CR if there are other necessary changes that need to happen in the same PR. don't want to cause friction with stuff like this
@@ -110,7 +110,7 @@ export class Tabs extends AbstractComponent<ITabsProps, ITabsState> { | |||
if (newIndex !== prevState.selectedTabIndex) { | |||
const tabElement = findDOMNode(this.refs[`tabs-${newIndex}`]) as HTMLElement; | |||
// need to measure on the next frame in case the Tab children simultaneously change | |||
setTimeout(() => { this.moveIndicator(tabElement); }); | |||
setTimeout(() => this.moveIndicator(tabElement)); |
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.
Looking at line 105, I'm wondering if it is appropriate to also update the moveTimeout
as well.
const style = wrapper.find(TabList).props().indicatorWrapperStyle; | ||
assert.isDefined(style, "TabList should have a indicatorWrapperStyle prop set"); | ||
// "translateX(46px) translateY(0px)" -> 46 | ||
const actual = Number(style.transform.split(" ")[0].replace(/\D/g, "")); |
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.
might this be a little more legible if you tested whether the actual value contains ${expected}px
?
instead of trying to parse the number out of the string (particularly brittle if we ever decide to change how the styles are applied), simply check whether 46px
appears inside the style string.
const style = wrapper.find(TabList).props().indicatorWrapperStyle; | ||
assert.isDefined(style, "TabList should have a indicatorWrapperStyle prop set"); | ||
// "translateX(46px) translateY(0px)" -> 46 | ||
const actual = Number(style.transform.split(" ")[0].replace(/\D/g, "")); |
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.
this code is identical to the test above. perhaps worth introducing a helper method that could do the entire check (plus my suggestion above)?
assertIndicatorPosition
?
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.
Agreed, thanks.
Not sure why my git fomo brought in all the commits, but it was just to check with master. |
something went wrong if it brought in all those commits... you might have to restart the branch and cherry-pick just the commits you care about. |
}); | ||
|
||
function assertIndicatorPosition(wrapper, TAB_INDEX_TO_SELECT) { |
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.
implicit any
args. please type them. and name thusly: (wrapper, selectedTabIndex)
); | ||
wrapper.setProps({ selectedTabIndex: TAB_INDEX_TO_SELECT }); | ||
// indicator moves via componentDidUpdate | ||
setTimeout(() => { |
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.
in another PR you seemed to use wrapper.update()
to get around this timeout. can we do that here?
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 can't do that here (it was before the moveIndicator
logic moved). setProps
already runs an update, but now that the indicator movement takes places in componentDidUpdate, so need to assert after the next frame.
f8e46eb
to
50fe50c
Compare
Add types and code cleanup | Preview |
* Fix Tabs indicator style when changed via controlled mode * Move the moveIndicator to componentDidUpdate * Add types and code cleanup
Add design responsivity
Fixes #32.
Fixes #47.