I have a button that when it has focus will make a div containing an input become visible:
function makeFocus() {
//document.getElementById('in').focus();
}
.edit-path-container {
display: none;
height: 100%;
}
.edit-path-btn:focus + .edit-path-container {
display: block;
}
.edit-path-container:focus-within, .edit-path-container:active {
display: block !important;
}
<button class="edit-path-btn " style="float:right" onfocus='makeFocus()'>click to show</button>
<div class="edit-path-container ">
<input id="in" type="text" value="test">
</div>
Here you can click in the input and edit the text, if you click away the container will disappear as intended.
I have added some JavaScript to give the input focus so the user can start typing straight away but the container never becomes visible. Is there a way to fix this?
3
Answers
I think you can do like that :
The problem with how it works is the blur event fires before the focus happens so the element hides as you try to focus it.
Only way I can see to get around it with how your HTML code is written is to add a temp class that makes it visible and you can then remove that temp class after you focus it or use all JavaScript.
Basic CSS I simplified but then added some more to remove the problematic
float
when placed on a page.Change summary:
'blur'
event