-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
preventDefault specified to work only for disabled && onSelect; it is… #2790
Conversation
As elsewhere, see #2711 (comment). |
Oh, @taion I've been meaning to ask you why. Why would we want to drop it across all onSelect?
I will update my PR with a fix for those as well. I saw some mention of this.props.onSelect in Carousel too, but I don't think it applies here. |
thanks! the reason why is that it ends up being more harm than help to prevent the link behavior. There are a few places where it still makes sense but I'm not sure which places. ALSO please make the PR against the |
You need to rebase this branch on We want to change it everywhere because we want all components here to offer similar APIs. It would be confusing if |
Thanks. I'm currently rebasing this branch onto next in my fork. Then I will re-open a PR with a request to merge my next into react-bootstrap's next. |
You need to run |
So I had done an interactive rebase before on this. I think that's what messed it up. I had done my changes off master. And then I rebased master onto next. Then I force pushed my next branch up to my forked repo. And now here we are. I'm wondering why all these other people's changes are still showing up as part of this PR. Maybe you could direct me as to how I can restrict the next branch to only my own commits. Perhaps you meant I should be creating a feature branch for just my own commits and then doing a PR to next with that feature branch? Let me know if you can decipher what I may have done wrong from above.
Panel, PanelGroup, and their respective spec files already got refactored with the latest from next, so I think their preventDefault issue is no longer an issue. Although their changes are still reflected in this PR. So let me fix the PR and sort this out properly. I will try this out in a few hours. |
Found the behavior in more items:
I'm going to investigate each of these and drop the preventDefault if possible. |
…ntDefault is clicked and for whether the navbar collapses when it is clicked.
I rebased and force pushed to your branch. You'll want to run something like:
assuming you don't have any other work you want to preserve on your current It turns out that due to #1769, we don't need this for The only one left is actually just |
src/NavItem.js
Outdated
@@ -28,12 +28,8 @@ class NavItem extends React.Component { | |||
} | |||
|
|||
handleClick(e) { | |||
if (this.props.onSelect) { | |||
e.preventDefault(); |
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.
we probably still want to do e.preventDefault()
if disabled
is set?
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.
Yes
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.
ok
test/NavbarSpec.js
Outdated
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(link)); | ||
|
||
expect(navItemSpy.getCall(0).args[0].isDefaultPrevented()).to.be.false; | ||
}) |
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.
missing semi here is causing lint failure
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
My preventDefault's snooping gave me the same result you found @taion
|
… onSelect. also modifying code so it only will preventDefault if element is disabled
src/NavItem.js
Outdated
if (this.props.onSelect) { | ||
if (this.props.onSelect && !this.props.disabled) { | ||
this.props.onSelect(this.props.eventKey, e); | ||
} else if (this.props.disabled) { |
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.
you can rewrite this a bit simpler as
if (this.props.disabled) {
e.preventDefault();
return;
}
if (this.props.onSelect)
this.props.onSelect(this.props.eventKey, e);
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 am for sure a fan of simpler.
src/PagerItem.js
Outdated
@@ -30,7 +30,7 @@ class PagerItem extends React.Component { | |||
handleSelect(e) { | |||
const { disabled, onSelect, eventKey } = this.props; | |||
|
|||
if (onSelect || disabled) { | |||
if (onSelect && disabled) { |
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.
again, check for disabled and return early
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.
oh okay
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.
There are still a few lint failures... broadly this code looks fine though
I think I fixed the linting errors. I ended up removing a Navbar test because it was a duplicate of another test. I had issues writing tests for the NavItem + PagerItem code branches involving e.preventDefault. Essentially, once you add a disabled property on a tag you can no longer Simulate a click on it, and that would throw off all my sinon spy and stub logic. If you can figure out a way to do it I'd be all ears. |
I also don't know why appveyor build is failing. It seems that build fix is outside of my control. The log mentioned something about trying to run an npm install command as administrator. |
AppVeyor is just flaky and janky. @jquense What's up with the |
ping @jquense |
LGTM, the log this was just a convenience for logging why chaining assertions. It gets removed in the enzyme switch anyway |
I resolved the merge commit. Good to go on my end now, just need signoff |
… a fix for issue #2711