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

Updating OutsideClickHandler to accept "flex" as a display prop #4

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

erikrahm
Copy link
Contributor

There are tons of different ways to handle the ternary for the style property on the main div, so feel free to chime in with something else if you think it would be more efficient.

@@ -112,7 +113,7 @@ export default class OutsideClickHandler extends React.Component {
return (
<div
ref={this.setChildNodeRef}
style={display === DISPLAY.INLINE_BLOCK ? { display } : undefined}
style={Object.values(DISPLAY).includes(display) ? { display } : undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is needlessly O(2n), this should be has(DISPLAY, display) instead; and part of the goal is that when it's "block", there's no style, since that's the default for divs

Copy link
Contributor Author

@erikrahm erikrahm Jun 13, 2018

Choose a reason for hiding this comment

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

@ljharb Fair enough, didn't want to bring in lodash unnecessarily but if it's alright with you then sounds good to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Absolutely not lodash; I meant the "has" package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how has would work here as it checks with hasOwnProperty, not for values, and the display prop being passed in would either be block, inline-block, or flex which are values not keys of the lookup table DISPLAY

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh true, that's a good point :-)

ok in that case, i guess this is fine (we'd need to use https://npmjs.com/object.values tho, and not the builtin) - altho it's probably better to build up a reverse object at module level, and then use has here.

@ljharb ljharb added the semver-minor: new stuff New stuff. label Jun 13, 2018
@ljharb ljharb requested a review from majapw June 13, 2018 21:09
@@ -112,7 +113,7 @@ export default class OutsideClickHandler extends React.Component {
return (
<div
ref={this.setChildNodeRef}
style={display === DISPLAY.INLINE_BLOCK ? { display } : undefined}
style={Object.values(DISPLAY).includes(display) ? { display } : undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since div is BLOCK by default, part of the original code path was specifically to not apply a style in the block case. Can we bring back that functionality here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can do

@erikrahm
Copy link
Contributor Author

Looks like a pre-commit hook did some formatting changes to some formatted code as well. Should I go back and revert that @ljharb @majapw ?

@erikrahm
Copy link
Contributor Author

Also added in an update to the README to match the addition of flex as an option

README.md Outdated
@@ -44,6 +44,6 @@ See https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Ev

If `useCapture` is true, the event will be registered in the capturing phase and thus, propagated top-down instead of bottom-up as is the default.

### display: `PropTypes.oneOf(['block', 'inline-block'])`
### display: `PropTypes.oneOf(['block', 'flex, 'inline-block'])`

Choose a reason for hiding this comment

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

Not a major deal since it's the README, but you're missing a closing quote on flex.

@ljharb
Copy link
Collaborator

ljharb commented Jun 13, 2018

@erikrahm yes, please revert any unrelated formatting changes.

@erikrahm
Copy link
Contributor Author

@ljharb Fixed

@ljharb
Copy link
Collaborator

ljharb commented Jun 13, 2018

Would you mind rebasing this down to a single commit?

There are tons of different ways to handle the ternary for the style property on the main `div`, so feel free to chime in with something else if you think it would be more efficient.

Performing requested updates to patch-1

Updating the README.md to match the addition of flex

README formatting issue

Adding a missing quite to README

Reverting formatting changes

Reverting formatting changes brought on by text editor using prettier.

Bold to italics

Reverting bold to italics in the README
@erikrahm
Copy link
Contributor Author

@ljharb squashed 😁

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

LGTM; we can optimize the Object.values usage later if needed, and we can add additional display types later as well.

@erikrahm
Copy link
Contributor Author

Yeah @ljharb , added in the object.values package you mentioned, but didn't want to add in the reverse object creation until later when the display prop gets finalized. Thanks for the merge!

@SoftwareBlair
Copy link

@ljharb Will this be merged soon?

@ljharb
Copy link
Collaborator

ljharb commented Jun 14, 2018

@brandonb81 it's been less than 24 hours since it was finalized, so I'm sure if you have some patience, it will be merged when it's ready.

@SoftwareBlair
Copy link

🖖🏻

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

LGTM!

@majapw majapw merged commit 4004189 into airbnb:master Jun 14, 2018
@erikrahm erikrahm mentioned this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants