I am learning react and am building a little electronic store. I have this tab called "View Store". When a user clicks on it, I want a little "peek-a-boo" column to appear and let the user view some text or pictures. When a user clicks anywhere else, I want this column to disappear.
What I do is define a state prop called "peekaboo". When a user clicks on my div, I set peekaboo to true. When a user blurs out, I set peekaboo to false, but what happens is that onClick works, but onBlur does not (store button dissappears but it never reappears when I am out of focus).
class ProductPage extends Component {
constructor() {
super();
this.peekClick = this.peekClick.bind(this);
this.peekHide = this.peekHide.bind(this);
this.state = {
peekaboo: false
};
}
peekClick = () => {
this.setState({peekaboo: true});}
peekHide = () => {
this.setState({peekaboo: false});}
render() {
return (
<div className="ProductPage">
<div className="ProductPage-Left">
{/* PROBLEM IS HERE */}
<div className="leftViewTab" onBlur={this.peekHide}>
{this.state.peekaboo ? (null) :
(<div className="leftViewText" onClick={this.peekClick}>
View Store
</div>)}
</div>
</div>
I looked at these stackoverflow posts for ideas: onclick() and onblur() ordering issue
I also found the onBlur idea on another question, but it does not seem to be working.