Skip to content

Fix selector for form floating background#38159

Closed
mdo wants to merge 1 commit intomainfrom
cleanup-floating-forms
Closed

Fix selector for form floating background#38159
mdo wants to merge 1 commit intomainfrom
cleanup-floating-forms

Conversation

@mdo
Copy link
Copy Markdown
Member

@mdo mdo commented Mar 2, 2023

This rewrites the selector to use :has() because .form-floating is a parent container, which has no :disabled state. The :disabled is handled on the individual form element.

That said, it'd be really cool if adding a disabled attribute on a parent element would disabled all the elements within—right now only fieldsets do that. And I genuinely just stumbled back into thinking about this... so what if we used fieldsets here in v6? Something to think about.

Anyway, the downside of using the :has() selector is browser compatibility right now. I'm not super worried about that as this could be seen as a progressive enhancement, but it's worth calling out. With the new selector, nothing is generated for disabled fields, so we avoid that problem entirely.

/cc @julien-deramond @louismaximepiton @jonnysp

@mdo mdo requested a review from a team as a code owner March 2, 2023 20:02
@julien-deramond julien-deramond mentioned this pull request Mar 2, 2023
14 tasks
@jonnysp
Copy link
Copy Markdown
Contributor

jonnysp commented Mar 2, 2023

The :has() selector is not enabled in Firefox https://developer.mozilla.org/en-US/docs/Web/CSS/:has#browser_compatibility

@mdo
Copy link
Copy Markdown
Member Author

mdo commented Mar 2, 2023

Something else to consider... when shadows are enabled, this pseudo element overlaps the input's shadow. Not sure yet how best to proceed with a fix here.

CleanShot 2023-03-02 at 11 51 21@2x

@jonnysp
Copy link
Copy Markdown
Contributor

jonnysp commented Mar 3, 2023

@mdo

i like it. 👌

the min-height for foating-labels textarea's could also be increased a little. then it's perfect.

grafik

Copy link
Copy Markdown
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel really exciting using this :has selector, however I feel like 85% might not be enough. For example I can't test it on FF LTS v.102. I don't know what's the policy on these features atm.

If we agree that we enable progressive enhancement, should we have a fallback ?

position: relative;

&:not(.form-control:disabled)::before {
&:has(.form-control:not(:disabled))::before {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split the rule in two ? .form-control::before and :has(.form-control:disabled)::before in order to avoid this:
image

So in the second rule we might only change the bg-color ?

@mdo
Copy link
Copy Markdown
Member Author

mdo commented Mar 24, 2023

Another option in #38313.

@mdo
Copy link
Copy Markdown
Member Author

mdo commented Mar 25, 2023

Closing for #38313.

@mdo mdo closed this Mar 25, 2023
@mdo mdo deleted the cleanup-floating-forms branch March 26, 2023 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants