dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
105 stars 36 forks source link

Parse :autofill and :-webkit-autofill #44

Closed domenic closed 2 years ago

domenic commented 3 years ago

https://html.spec.whatwg.org/#selector-autofill

They should probably never match anything in nwsapi, but it'd be good if they didn't throw exceptions

dperini commented 3 years ago

@domenic I currently have two groups to categorize this pseudo-class:

which one group do you believe this pseudo-class should fall under ?

And ... could we assume that one of these checks:

is a good enough resolver for correctly matching this pseudo-class ?

domenic commented 3 years ago

I think these pseudo-classes should never match, at least in jsdom. The spec says

The :autofill and :-webkit-autofill pseudo-classes must match input elements which have been autofilled by user agent. These pseudo-classes must stop matching if the user edits the autofilled field.

and there's no way to detect that from JavaScript. The proposal of input.defaultValue.length > 0 will match the following HTML (even without any autofilling taking place):

<input type="text" value="some default value">

(but it should not). And the proposal of input.defaultValue.length > 0 && input.defaultValue != input.value will match the following:

<input type="text" value="some default value">
<script>
document.querySelector("input").value = "a non-default value";
</script>

(but it should not).

domenic commented 3 years ago

which one group do you believe this pseudo-class should fall under ?

Sorry for missing this question. I don't think those categories exist in any spec, so it's just a matter of taste, right? I guess I would say "user interface and form pseudo-classes".

Lagyu commented 2 years ago

Any progress? I really wish if I could mute the error from jsdom when I use those pseudo-classes.

Lagyu commented 2 years ago

:autofill and :-webkit-autofill should be categorized into input pseudo-classes for browsers only attach them to input elements. MDN also do so. https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes#the_input_pseudo-classes

We don't need any check with them because jsdom has nothing to do with autofill.

Note that Chrome removes :autofill and :-webkit-autofill of all input element when user focuses on any one of input, while Firefox does not remove on focus. Firefox removes those pseudo-classes on value change, and Firefox only removes the pseudo-classes from the only one (changed) input element.

dperini commented 2 years ago

@domenic I am going to release 2.2.2 to npm. I did run jsdom + wpt tests but a further check will let me sleep ;-)