I could not reproduce the problem but I tried to. I have a Material UI element with a child I've added inside it. The icon/child is the X in the corner. The tab/parent is the surrounding box.

Two problems:
- I want to click on the child but the parent covers it entirely and the child is not getting clicked.
- Even if it is clicked, it's inside the
Tabicon field and this seems to disrupt the click anyway.
handleIconClick(){
console.log('click')
}
renderIcon() {
return (
<div
tabIndex="-1"
className="icon-wrapper"
onClick={this.handleIconClick.bind(this)}
>
<Icon />
</div>
);
}
...
<Tab icon={this.renderIcon} onMouseMove={this.mouseEvent.bind(this)} label={tab.label} key={i}></Tab>})}
I tried to solve this by using the onMouseMove event on the Tab above by using it like so.
- Positioning the child in the top corner of the parent as shown.
- When the cursor gets near the child in the corner, manually target the child with this. (The x & y vals are arbitrary and specific to this case)
function mouseEvent(e) {
var rect = e.target.getBoundingClientRect();
var x = e.clientX - rect.left; //x position within the element.
var y = e.clientY - rect.top; //y position within the element.
let trigger = document.querySelector('.icon-wrapper')
let parent = document.querySelector('.MuiButtonBase-root-59')
if(y <= 27 && x >= 60){
trigger.focus()
} else {
trigger.blur()
}
}
If I move the Icon out of the tab onto the page it begins to work, so I don't know if it is the parent that is blocking it, or if it's the Tab icon field causing the problem.
The focus appears visually when I get in the range of the above coords but the click never fires. It seems like the mouse only has access to the parent yet when mousing over the icon with the above mouseover event I'm logging console.log(document.activeElement.className) and close-icon appears, which is correct. So then it seems like it's the function that is not firing.
I need to be able to click the tab as it has its own click handler (not shown), so it cannot be disabled.
I haven't found a way to add to the Tab outside of these fields, however if it's possible
it is possible it could be the answer.
Really I want to do is close the tab on click which seems like something pretty basic.