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 Tabs indicator style when changed via controlled mode #48

Merged
merged 6 commits into from
Nov 11, 2016

Conversation

cyu06
Copy link
Contributor

@cyu06 cyu06 commented Nov 7, 2016

Fixes #32.
Fixes #47.

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); });
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Will update.

Copy link
Contributor

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));
Copy link
Contributor Author

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, ""));
Copy link
Contributor

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, ""));
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, thanks.

@cyu06
Copy link
Contributor Author

cyu06 commented Nov 10, 2016

Not sure why my git fomo brought in all the commits, but it was just to check with master.

@giladgray
Copy link
Contributor

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) {
Copy link
Contributor

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(() => {
Copy link
Contributor

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?

https://github.com/palantir/blueprint/pull/41/files#diff-c5ca5cbfe301c1ea705d793f86ff1847R113

Copy link
Contributor Author

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.

@cyu06 cyu06 force-pushed the cyu/fix-controlled-tabs-indicator branch from f8e46eb to 50fe50c Compare November 10, 2016 15:10
@blueprint-bot
Copy link

Add types and code cleanup | Preview
core coverage | datetime coverage

@giladgray giladgray merged commit 6cd5d8f into master Nov 11, 2016
@giladgray giladgray deleted the cyu/fix-controlled-tabs-indicator branch November 11, 2016 18:24
greglo pushed a commit to greglo/blueprint that referenced this pull request Dec 12, 2016
* Fix Tabs indicator style when changed via controlled mode

* Move the moveIndicator to componentDidUpdate

* Add types and code cleanup
peterblazejewicz pushed a commit to peterblazejewicz/blueprint that referenced this pull request Dec 20, 2017
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.

4 participants