#35008 closed Cleanup/optimization (fixed)

Minifiers break django contrib admins UI

Reported by: Raphaël Stefanini Owned by: Mariusz Felisiak
Component: contrib.admin Version: 4.2
Severity: Normal Keywords: UI admin minified css
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

I have been using a HTML minifier on django's output and it breaks some UI elements in django's shipped admin by stripping some default attributes, mainly by removing type="text" on inputs, since it is a default html input attribute.
This affect anyone who would use a minifier either as middleware or as CDN feature, and the logic is clear, you don't have to keep default html attribute.
The problem is that django repo CSS rules don't take that in account and it assume for all attributes to be present.
Django would need to have a CSS rule stating input:not([type]), input[type=text] instead of just input[type=text] for the minified version to match the original UI.

I have found only three places in django.contrib.admin that would need a CSS update, so I believe it is an easy fix:

// base.css:485
input:not([type]),
...
{
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px 6px;
    margin-top: 0;
    color: var(--body-fg);
    background-color: var(--body-bg);
}
// base.css:495
input:not([type]):focus,
...
{
    border-color: var(--body-quiet-color);
}
// responsive.css:177
.form-row input:not([type]),
...
{
    box-sizing: border-box;
    margin: 0;
    padding: 6px 8px;
    min-height: 2.25rem;
    font-size: 0.875rem;
}

I create this ticket after having discussed the issue here https://github.com/adamchainz/django-minify-html/issues/165

Change History (10)

comment:1 by Mariusz Felisiak, 13 months ago

It was already proposed, check out comment. I'm pretty sure that we will remove them in some cleanup PR titled "Removed unused CSS rules ...". We normally don't add CSS rules not used by Django itself.

Last edited 13 months ago by Mariusz Felisiak (previous) (diff)

comment:2 by Aman Agrawal, 13 months ago

Owner: changed from nobody to Aman Agrawal
Status: newassigned

comment:3 by Mariusz Felisiak, 13 months ago

Triage Stage: UnreviewedAccepted

Tentatively accepted.

comment:4 by Raphaël Stefanini, 12 months ago

What about re-opening this PR then? https://github.com/django/django/pull/17183

comment:5 by Mariusz Felisiak, 12 months ago

Raphaël, feel-free to send a new PR (based on PR17183). We need to at least add a comment to the CSS files.

comment:6 by Raphaël Stefanini, 12 months ago

comment:7 by Mariusz Felisiak, 12 months ago

Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak, 12 months ago

Has patch: set
Owner: changed from Aman Agrawal to Raphaël Stefanini

comment:9 by Raphaël Stefanini, 12 months ago

Owner: changed from Raphaël Stefanini to Mariusz Felisiak

comment:10 by GitHub <noreply@…>, 12 months ago

Resolution: fixed
Status: assignedclosed

In 5c6906c:

Fixed #35008 -- Added CSS rule for <input> HTML tags with no type.

Minifiers remove the default (text) "type" attribute from "input" HTML
tags. This adds input:not([type]) to make the CSS stylesheet work the
same.

Note: See TracTickets for help on using tickets.
Back to Top