Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/contrib/admin/templates/admin/search_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div id="toolbar"><form id="changelist-search" method="get" role="search">
<div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img src="{% static "admin/img/search.svg" %}" alt="Search"></label>
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar"{% if cl.search_help_text %} aria-describedby="searchbar_helptext"{% endif %}>
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar"{% if cl.is_popup %} autofocus{% endif %}{% if cl.search_help_text %} aria-describedby="searchbar_helptext"{% endif %}>
<input type="submit" value="{% translate 'Search' %}">
{% if show_result_count %}
<span class="small quiet">{% blocktranslate count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktranslate %} (<a href="?{% if cl.is_popup %}{{ is_popup_var }}=1{% if cl.add_facets %}&{% endif %}{% endif %}{% if cl.add_facets %}{{ is_facets_var }}{% endif %}">{% if cl.show_full_result_count %}{% blocktranslate with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktranslate %}{% else %}{% translate "Show all" %}{% endif %}</a>)</span>
Expand Down
14 changes: 14 additions & 0 deletions tests/admin_changelist/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,20 @@ class ChildAdmin(admin.ModelAdmin):
cl = m.get_changelist_instance(request)
self.assertEqual(cl.get_ordering_field_columns(), {2: "asc"})

def test_search_bar_autofocus_on_popup(self):
self.client.force_login(self.superuser)
url = reverse("admin:auth_user_changelist")
for data, autofocus_expected in (
(None, False),
({IS_POPUP_VAR: "1"}, True),
):
with self.subTest(data=data):
response = self.client.get(url, data=data)
if autofocus_expected:
self.assertContains(response, 'id="searchbar" autofocus')
else:
self.assertNotContains(response, 'id="searchbar" autofocus')


class GetAdminLogTests(TestCase):
def test_custom_user_pk_not_named_id(self):
Expand Down