-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Drawer routing and onClick issues when using with react.js #644
Comments
So It seems that the issue is caused by componentClickHandler calling stopPropagation(). I have this for a quick fix right now: in material/drawer/slidable/foundation.js
in material/drawer/temporary/foundation.js
Then importing like this: I am not sure if this has any bad side effects on other behaviors of the drawer, so take it with a grain of salt. Edit: had the same issue with the dialog component, too. To resolve this, I did pretty much the same but with the |
Hi @j-o-d-o , this is definitely a bug and it was reported in #579 as well. I think your proposed solution make a lot of sense and it seems not changing the behavior for temporary and persistent drawer. We would like to accept a PR for the fix if you are willing to help out! Basically it should include:
Thanks! This will help us unblock quite a few react.js users! |
#658 submitted a pull request, but need help on what to do to fix the unit tests which break because of deleting the click handler |
@j-o-d-o did this actually work in your React implementation? |
At its core, all react-router-dom's handleClick(e) {
e.preventDefault();
}
render() {
return (
<Link to='/bar' onClick={this.handleClick}>Bar</Link>
);
} @j-o-d-o can you toss up a codepen implementation of your use case so I can help resolve this issue? I think we need more work than just ripping out the click handlers in |
That won't work because in my case the
But that being said, I all with you! This is very hacky. Using a html class to determine what to do? Not that great imho. But just calling stopPropagation() on the drawer click handler does not seem like the right solution either. There already is a "drawerClickHandler_", so there is definitely a more elegant solution to this issue. I just needed a quick fix for my application. I will try to put up a codepen example. |
Okay, I looked at it again. What do you think about this possible solution? in
in
|
Alright, sorry for spamming here, but this didn't let me rest ;). First off, two coderpens:
After some research on event order, capture & bubble phase. (https://w3c.github.io/uievents/) and how react.js is handling events... Here is why this issue exists: |
Is it going to be fixed? Full ugly code i have used: componentDidMount() {
document.querySelector('.mdc-temporary-drawer').addEventListener(
'click',
this._fixClickHandler = e => {
const target = e.target
if (
target.parentElement.tagName === 'NAV' &&
typeof DRAWER_LINKS_ACTIONS[target.id] === 'function'
) {
e.stopPropagation()
DRAWER_LINKS_ACTIONS[target.id]()
}
},
// use capturing event phase to fix
true
)
}
componentWillUnmount() {
document.querySelector('.mdc-temporary-drawer')
.removeEventListener('click', this._fixClickHandler)
} Can somebody suggest more simple solution here? |
Facing the same issue. @dimik Hi, I'm trying your solution but I don't fully understand what's DRAWER_LINKS_ACTIONS. Would you mind documenting that part a bit more? Thanks for your solution. |
Rolling this into #794 as that seems to be the root of the problem here as well. Please move conversation there. Closing. |
@RobertoIDL DRAWER_LINKS_ACTIONS it's just a regular JS object to store event handlers by element id. Because you a not able to get event handler from e.target const DRAWER_LINKS_ACTIONS = {
'_nav_id_1_': (e) => {},
'_nav_id_2_': (e) => {},
'_nav_id_3_': (e) => {},
} |
Are you sure you're using the latest version of MCW? |
Using v0.16.0 |
Link to my code sandbox
|
I am using MDC with react.js and have an Issue with the mdc drawer. I striped down the react component to the basics:
Issue
The drawer opens and closes as expected. But the
<NavLink/>
and<Link/>
are refreshing the page instead of routing without page refresh. Also, the onClick event callingthis.test()
is not working. Both things work as expected when putting them into<div className="mdc-toolbar__row">
.EDIT: The Issue occurs with Persistent & Temporary drawer. The Permanent drawer does not have these issues.
MDC-Web Version
material-components-web: 0.10.0
material: 0.1.1
Browser(s)
Chrome (Version 58.0.3029.96 (64-bit))
Firefox (53.0.2 (32-Bit))
OS
Win 10
The text was updated successfully, but these errors were encountered: