django-admin-autocomplete-filter icon indicating copy to clipboard operation
django-admin-autocomplete-filter copied to clipboard

In Django 4.1 the focus isn't set to the select2 input when clicking on the set filter box.

Open selected-pixel-jameson opened this issue 2 years ago • 3 comments

There is a UX issue when I click on the filter the select2 input field doesn't gain focus. I'm unable to tab to put focus down to that field either. I have to use the mouse to manually click on that second input field in the drop down after I just clicked on the input.

Notice in this screenshot how there is no cursor in the second input? Screenshot 2023-01-12 at 9 50 43 AM

And this is from our current production site. Notice how the cursor is showing in the screenshot? Screenshot 2023-01-12 at 9 55 18 AM

While this seems like a insignificant issue it is actually rather large because end-users of the admin panel are using this filter very often and having to make a secondary click is just going to cause issues. I would be willing to submit a pull request for this, but I'm not even sure where to start.

Thank you.

selected-pixel-jameson avatar Jan 16 '23 13:01 selected-pixel-jameson

this seems like an issue from django autocomplete widget.

For now, I think you can write a custom js to set the focus manually. for instance with jquery:

function setFocus(event) {
    const el = event.currentTarget
    const isOpen = el.getAttribute("aria-expanded") === "true"
    if (isOpen) {
        document.querySelector(".select2-search__field").focus()
    }
}

$('.select2-selection').click(function (event) {
    setFocus(event)
})

$('.select2-selection').keyup(function (event) {
    if (event.keyCode == 13) {
        setFocus(event)
    }
})

madeyoga avatar Jan 18 '23 06:01 madeyoga

@madeyoga Are you referring to the django-autocomplete-light package?

selected-pixel-jameson avatar Jan 18 '23 15:01 selected-pixel-jameson