I implemented a focusable div to hide the div, if the user clicks outside of it. I’m not sure if this is a valid approach.
The event listeners for blur and focus are not triggered …
What do you think?
@Tag("Div")
public class FocusableDiv extends Div implements Focusable<Div> {
private Div focusableDiv;
@Override
public Element getElement() {
if(focusableDiv == null) {
focusableDiv = new Div();
}
return focusableDiv.getElement();
}
@Override
public void focus() {
this.setVisible(true);
}
@Override
public void blur() {
this.setVisible(false);
}
public Div getFocusableDiv() {
return focusableDiv;
}
public void setFocusableDiv(Div focusableDiv) {
this.focusableDiv = focusableDiv;
}
}
Thank you! The focusing and blur works now.
But I ran into a new problem. The element which triggers the focus is also responsible for hiding the div, if clicked again.
The click listener on this element is triggered after the blur listener on the focused div. So it’s not possible to hide the div via that element (because it’s always closed by blur and then opened by the click listener again).
I guess there is no way around that …
Is it possible to detect the clicked element inside the blur listener?