Skip to content
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

[selectors-4] Should :user-valid and :user-invalid apply to form and fieldset elements? #9257

Open
josepharhar opened this issue Aug 28, 2023 · 11 comments · May be fixed by #9308
Open

[selectors-4] Should :user-valid and :user-invalid apply to form and fieldset elements? #9257

josepharhar opened this issue Aug 28, 2023 · 11 comments · May be fixed by #9308
Labels
selectors-4 Current Work

Comments

@josepharhar
Copy link
Contributor

The selectors-4 spec says this here after the definition of :user-valid and :user-invalid: https://drafts.csswg.org/selectors-4/#issue-df919919

Clarify that this (and :invalid/:valid) can apply to form and fieldset elements.

I made a quick demo here: https://jsfiddle.net/jarhar/Lohxsz2n/30/
It looks like :valid and :invalid apply to form elements, whereas :user-valid and :user-invalid don't apply to forms. This behavior is the same across chrome, firefox, and safari.

Should we standardize this behavior which happens to already be interoperable? Or should we make changes to make :user-valid and :user-invalid apply to forms and fieldsets?

@nt1m

@nt1m
Copy link
Member

nt1m commented Aug 28, 2023

The newly added HTML spec currently explicitly does not apply the :user-* pseudos on fieldset / form, I haven't really thought too much about this personally.

If we really wanted to define those pseudos on fieldset / form, they could be defined as the equivalent of :has(:user-invalid) or :has(:user-valid) for the respective elements. From an user experience perspective that probably makes sense, though status quo is fine too.

cc @pxlcoder @emilio Any opinions?

@emilio
Copy link
Collaborator

emilio commented Aug 31, 2023

I think I have a slight preference for making form / fieldset never match these. The code tracking these in gecko is not amazing, I'm not excited about making it more complicated, and I've never seen a use case for these... But if there are use cases that need this I'd be ok supporting these.

I don't think it's fine to make these effectively :has(:user-valid) / :has(:user-invalid), however. That allows a form / fieldset to match both at the same time. Probably should be:

  • :user-invalid matches if there's at least one :user-invalid associated element underneath.
  • :user-valid matches if there's at least one :user-valid associated element underneath and there are no :invalid elements underneath or so (so :valid:has(:user-valid)?)

@josepharhar
Copy link
Contributor Author

I'm happy to make :user-valid and :user-invalid not match forms and fieldsets. After all, this is already the interoperable behavior and we just need spec and tests for it. Nobody so far has really advocated for them applying to forms and fieldsets yet as far as I can tell.

I am adding a WPT here: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
How exactly should we change the spec?

@emilio
Copy link
Collaborator

emilio commented Sep 4, 2023

I think they don't match per spec already right? https://html.spec.whatwg.org/#selector-user-valid mentions it only matches input, textarea and select elements.

@josepharhar
Copy link
Contributor Author

Yeah, we just need to do something about this note in the CSS spec: https://drafts.csswg.org/selectors-4/#issue-df919919
Since it's already defined as not matching in the HTML spec, should we just delete the note in the CSS spec? Or does the CSS spec also need to say which elements it matches?

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 4, 2023
…ldset

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 4, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
@emilio
Copy link
Collaborator

emilio commented Sep 4, 2023

Yeah, we just need to do something about this note in the CSS spec: https://drafts.csswg.org/selectors-4/#issue-df919919 Since it's already defined as not matching in the HTML spec, should we just delete the note in the CSS spec? Or does the CSS spec also need to say which elements it matches?

Why are these pseudo-classes defined in two places, incompatible with each other?

I'd remove the CSS spec section on these, or make it point to html, probably?

@josepharhar
Copy link
Contributor Author

Sounds good, I opened a PR to do so here: #9308

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 6, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
aarongable pushed a commit to chromium/chromium that referenced this issue Sep 6, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 6, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 6, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 13, 2023
…d fieldsets, a=testonly

Automatic update from web-platform-tests
Add WPT for validity pseudos on forms and fieldsets

This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}

--

wpt-commits: d1f9cf3e9067d21eeae980996fed25b45358a4de
wpt-pr: 41801
vinnydiehl pushed a commit to vinnydiehl/mozilla-unified that referenced this issue Sep 14, 2023
…d fieldsets, a=testonly

Automatic update from web-platform-tests
Add WPT for validity pseudos on forms and fieldsets

This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}

--

wpt-commits: d1f9cf3e9067d21eeae980996fed25b45358a4de
wpt-pr: 41801
@kbrilla
Copy link

kbrilla commented Sep 19, 2023

I know It is already resolvers but what about additional :user-visited that would work on same heuristic as :user-valid and :used-invalid but just represent that user visited the field with enough interest. But then would it not be sufficient to use :user-visited:valid ? :user-visited Would also work with framework like angular that do not modify native user valid.

@nt1m
Copy link
Member

nt1m commented Sep 19, 2023

@kbrilla Can you file a separate issue for this?

@kbrilla
Copy link

kbrilla commented Sep 19, 2023

@kbrilla Can you file a separate issue for this?

Will do

@morki
Copy link

morki commented Oct 5, 2023

I think this would be good to have, bacause we can use <input>'s, <select>'s and other form elements attribute form to associate other form, we use it heavily and using CSS :has selector is pointless in this case.

<form id="form1>
  <input>
  <input form="form2">
</form>
<form id="form2>
  <input>
  <input form="form1">
</form>
<input form="form1">
<input form="form2">

Lightning00Blade pushed a commit to Lightning00Blade/wpt that referenced this issue Dec 11, 2023
This patch adds tests for :valid, :invalid, :user-invalid, and
:user-valid on <form>s, <fieldset>s, and <input>s.

This is being discussed here:
w3c/csswg-drafts#9257
This behavior is already interoperable, so this test should pass in all
browsers.

Bug: 1156069
Change-Id: I02a4ae0d628b37196ef269e066b3272114ed0b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4839394
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1192951}
@fantasai fantasai added the selectors-4 Current Work label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
selectors-4 Current Work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants