-
Notifications
You must be signed in to change notification settings - Fork 6
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
💄 [#1556] Styling for selects with empty option selected #796
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,8 @@ select { | |
option:checked { | ||
color: var(--font-color-body); | ||
} | ||
|
||
&.muted { | ||
color: var(--color-mute); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<select name="{{ widget.name }}" {% if widget.value.0 == "" %}class="{{widget.attrs.class}} muted"{% endif %}{% include "django/forms/widgets/attrs.html" %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %} | ||
<optgroup label="{{ group_name }}">{% endif %}{% for option in group_choices %} | ||
{% include option.template_name with widget=option %}{% endfor %}{% if group_name %} | ||
</optgroup>{% endif %}{% endfor %} | ||
</select> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It doesn't seem to be possible to style a
<select>
based on the selected<option>
using CSS and I didn't want to create a custom widget that would have to be set on each instance of...ChoiceField
, so I opted for this approach insteadThere 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.
Note: We put all our Form Component templates in this project in this particular directory here: src/open_inwoner/components/templates/components/Form
So I don't think we should put anything into the Django templates Dir.
Also: with this approach we need to create a 1st option inside all Selects that should start with some kind of empty default, like here:
http://127.0.0.1:8000/mijn-uitkeringen/
So I guess you should add one there :-)
Not sure what to call it, perhaps "Select month".
Same for:
http://127.0.0.1:8000/mijn-uitkeringen/jaaropgaven/ "Select year"
More pages with selects, that are probably allright:
http://127.0.0.1:8000/mijn-profiel/contacts/
http://127.0.0.1:8000/mijn-profiel/actions/
And ">> Mijn profiel >> Mijn acties >> Bewerk [Actie title]"
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.
Just to be sure: do you mean that having
Sep 2023
not muted as the initial value would be okay as well? I could modify the widget to check if the initial value is empty or not and apply the class with the muted styling based on thatI checked the contacts page, the change I mentioned above would cause "Alle" to be displayed muted, because it's value is
""
. Is this correct?I put the template in
templates/django/forms/widgets/select.html
to override the default widget that Django uses under the hood, which makes this change available for all selects without having to manually add classes to each occurring select. I'm not sure if there is another way to override a default Django widget without having to monkey patch stuff, which seems like it would be unnecessary in this case in my opinion.If it turns out we do not want this styling applied to each select or if there is no generic solution, the only solution is probably to add the muted class to all selects manually (which could be kind of a chore, I'm not sure how many selects there are 😛)
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.
Indeed: the first option in the selects in the Maandopgaven/Jaaropgaven should not be muted because it's already showing a real option - the muted style is a UX indication, so should only be applied to a default option to indicate to the user something can be selected/filtered.
I'm not sure anymore but I tried to tackle this with CSS-only a couple of months ago and I think I found that some selects weren't using the value attribute at all, which made them empty, which meant that too many of them had a zero value so it would show the mute style too often.
In my previous answer I posted all of the places that have a Select; so currently i'd think there's only a maximum of 6 selects in the entire project.
And yes: I'd say 'alle' for Contacts should be muted because it means nothing has been filtered by the select yet.
As for the location of the templates and if we just simply wish to override: I am not sure - I'd have to ask @alextreme or @Bartvaderkin.
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.
Ah alright, in that case I think all of them are displayed correctly:
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.
If that's true then i will approve this :-) for new selects we'll need to make a correct model with values I guess.