New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #35189 -- Render admin collapsible fieldsets with <details>. #17910
base: main
Are you sure you want to change the base?
Conversation
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
627eb66
to
ffb0a66
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Hi @MHLut I think this looks really promising thank you ⭐ I can see on your PR that in RTL we have this (notice that 'Collapsible' is on the left) Previously 'Collapsible' was on the right: I am also not sure if the collapse icon (> triangle thingy) should be on the left, so before Fields in the right to left case (maybe @sakhawy might be able to tell us 🙏 ) You might need to look into |
(on further thought, I think the triangle is in the correct place for RTL languages but Moe is welcome to confirm) |
@sarahboyce I guess it "feels off" because we're used to seeing dropdowns with the triangle after the text and not before it :D One reason for checking the
I think it's the reason 'Collapsible' is on the left when |
69349a0
to
81f1b78
Compare
@sarahboyce @sakhawy Thanks for the heads-up. I can't remember why I put the The triangle is—as Moe mentioned—part of FYI: I'm currently doing some free-form CSS experiments for forced-colors mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look much at the code, or look at it on a screen.
From an accessibility standpoint I think we're good with this approach. The outline seems a little odd still (that there are multiple h3s per link, rather than one h3 and then going to h4 or something similar) but I think this is better than what we currently have and shouldn't block this merge - to be honest I'm not even sure if it's a problem at all, I could be totally wrong.
If I find time before someone else I will also review the code.
b450dd2
to
13f2707
Compare
@@ -2306,8 +2311,7 @@ The ``InlineModelAdmin`` class adds or customizes: | |||
A list or tuple containing extra CSS classes to apply to the fieldset that | |||
is rendered for the inlines. Defaults to ``None``. As with classes | |||
configured in :attr:`~ModelAdmin.fieldsets`, inlines with a ``collapse`` | |||
class will be initially collapsed and their header will have a small "show" | |||
link. | |||
class will be initially collapsed using an expandable widget. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@django/triage-review InlineModelAdmin.classes
references ModelAdmin.fieldsets
which has a versionchanged
note, do you think that same version changed note is also required here for InlineModelAdmin.classes
?
Also suggestions are welcome around tweaking the release notes/version changed note/docs updates. I've done my best but not quite mastered the art of good docs. ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also unsure about this. If one source references the other, then it's probably OK to list a versionchanged with the latter only as a single source of truth. But I am unaware of Django's practices here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor thoughts. Looks great though!
13f2707
to
16dfc63
Compare
Hello @MHLut! Thank you so much for your work on this, for all the investigation and sharing your thoughts in the description and in Discord. I read thru the Discord thread (I may have missed something), and while I acknowledge that you said the following:
I honestly dislike the "Fields" summary. It feels (to me, I know, very objectively) very unpolished in terms of UI, mainly because the fieldset is supposed to be collapsed and yet Django is "stubbornly" showing just a peak, a little more of it. I think is, to some extent, important to keep the previous "implicit agreement" that a collapsed fieldset would only show the fieldset name and nothing else. With that in mind, do you think there is a way to have Example 3 working (purely in terms of UI) without duplicating the fieldset name? Basically have Example 3 without the words highlighted in red: Happy to coordinate a chat or meet if you feel that discussing this IRL(ish) would be easier. |
@nessita Thank you for your feedback. As far as I have seen, there is no good way to do the third option without repeating information. Here is why. The HTML requires the following items:
We can place the heading inside the legend. I picked the solution that looks the most streamlined (in my opinion) and has the least replication. By ensuring that the heading comes first in the structure, we don't have to add the heading contents to any of its child elements. (Since the fieldset name has already been announced) I prefer solution 2 to the old UI, so let's agree to disagree there. Nb. If desired, "Fields" could be replaced with another text. |
Thanks for these details. To be honest, I'm struggling to understand why all these elements are necessary. Based on the Discord messages I read, it seems there are two primary reasons: firstly, to enable the use of CSS for selectors and to handle the hide/show behavior without JavaScript, and secondly, to ensure proper accessibility and assist screen readers. However, I'm still not entirely clear on why each element is essential. I'm unsure how to experiment with this and comprehend the consequences of removing each item individually. To try to understand a bit more, I copied the HTML from your codepen for Example 3, and below these I put some questions: <section>
<h2>Example 3: Details outside (no JS)</h2>
<div id="details-example-outside" class="example example--details-outside">
<details open="">
<summary>Address fields</summary>
<fieldset class="module aligned collapse">
<h3>Address</h3>
<div class="description">Optional description.</div>
<div class="form-row field-address_line_1">...</div>
<div class="form-row field-address_line_2">...</div>
<div class="form-row field-city">...</div>
<div class="form-row field-state">...</div>
<div class="form-row field-zip_code">...</div>
<div class="form-row field-country">...</div>
</fieldset>
</details>
</div>
</section>
With the above, and changing "Address fields" -> "Address", I think we would have a nice solution.
This I'm not sure what it means, sorry. Could you please help me understand? An example would certainly help me!
Sure.
I agree that the hint about the expandable area is necessary, but I think the triangle in the "fieldset title row" (the blue one with white letters) accomplish that perfectly. There is no need for an extra row IMHO. Having yet another row (white background in example 2) seems unnecessary (from an UI POV) and doesn't provide any useful information (I know we can change the text, I replied about this further down). I consider this a regression, in that Example 2 makes the interface feel cluttered and can be confusing for users who expect collapsible sections to minimize the amount of visible content, especially when vertical space is limited. I believe it's unnecessary to append or mention "fields" anywhere, as it seems redundant. This is similar to how the admin doesn't append "Model" everywhere because it's implied.
Yes, absolutely, though I can't think of a text to put in there that would justify the extra row. Do you have any ideas? |
I had a (very quick!) look into this. The As for the With removing the |
Notes regarding UI changes to the third proof of concept (link in top description): I tried to combine the fieldset and details elements, but the Firefox accessibility inspector threw warnings. The problem is that a fieldset needs a legend to describe its contents to assistive technology, and the legend should be its first child. The same goes for details: the summary describes its contents and should be the first child. When putting the legend inside the summary, the accessibility inspector did not recognize it as a label. I also tried to attach the fieldset name to the fieldset through I don't see how we can use the third UI solution without sacrificing accessibility. NB. Regarding |
@MHLut could we use a "complete" solution for the third option without sacrificing accessibility by hiding the |
@nessita The We cannot intertwine the I also would prefer to keep the If we sacrifice the I have tried several things and don't know what else would be good. |
@MHLut Thank you. Could you please, when you have some time, push changes in another branch with what you have for solution 3? Ideally this temporary branch would have a complete solution in terms of accessibility (ie all the required HTML elements for assistive technologies would be present). I'd like to see how it looks and use it a bit, if possible. |
This is an alternative for django#17910, with a UI that looks more like the original Django.
Per @nessita's request, I have updated the PR (in a separate commit for now) with a new UI style. After a discussion with a blind developer, I think I have found a middle group that works for screen readers without creating a UI regression. Note: If anyone wants to discuss his suggestions in more detail, we can do that in person or an accessibility meeting (I wouldn't copy/paste a Slack thread here or in Discord). See these notes I added to the PR: Accessibility notes: I discussed this solution with a blind developer. He suggested we replace Due to styling issues, I had to change the heading level of inline fieldsets to Other notes: This solution hinges on adding a unique ID to a fieldset heading so that we can use |
This is an alternative for django#17910, with a UI that looks more like the original Django. Hat-tip to James Scholes for the advice.
Tagging @jscholes as my aforementioned advisor. |
This is an alternative for django#17910, with a UI that looks more like the original Django. Hat-tip to James Scholes for the advice.
Apologies for the failed tests; I've added some classes to existing headings, but the tests do not like it. I will fix these later, but you can test this new UI design already! |
This is an alternative for django#17910, with a UI that looks more like the original Django. Hat-tip to James Scholes for the advice.
…elements. Thanks to Sarah Boyce and Tom Carrick for the review.
This is an alternative for django#17910, with a UI that looks more like the original Django. Hat-tip to James Scholes for the advice.
TL;DR: Improve the accessibility of admin fieldsets and collapse them with a native HTML implementation.
Related tickets and PRs
Related items:
Important facts
A new translation "Fields" (context "form fields") was introduced.Changed in second commit.Known issues
forced-colors
mode..collapse. h3
informs.css
was copied from.module h2, .module caption, .inline-group h2
inbase.css
.TheFixed in the second commit.<h3>
heading in stacked inlines should be a<h4>
; however, it was originally a<h2>
, so it's still better than before.A potential UX issue could be that the clickable area of the fieldset has moved: You click on the details toggle ("fields") instead of the blue fieldset header.Changed in the second commit.Screenshots
A collapsible fieldset; collapsed
A collapsible fieldset; expanded
A fieldset that cannot be collapsed due to a validation error
A collapsible fieldset inside a stacked inline; collapsed
A collapsible fieldset inside a stacked inline; cannot be collapsed due to a validation error