Skip to content

[css-conditional] Make CSSSupportsRule expose whether its condition is met #4240

Closed

Description

@SebastianZ

You currently can't tell directly from a CSSSupportsRule whether the condition is actually fulfilled or not. To do that you have to use CSS.supports(cssSupportsRule.conditionText).

Therefore I suggest to add a getter to CSSSupportsRule (or rather to CSSConditionRule which is overwritten by the derived interfaces) that returns whether the condition is met or not, e.g supported or fulfilled.

Sebastian

Activity

  1. FremyCompany commented on Aug 26, 2019

    @FremyCompany
    Contributor

    Sounds reasonable to me

  2. SebastianZ commented on Jun 2, 2022

    @SebastianZ
    ContributorAuthor

    I think that's a very straight-forward addition. So, setting Agenda+ to discuss it in a call.

    Sebastian

  3. fantasai commented on Jun 7, 2022

    @fantasai
    Collaborator

    Maybe .isTrue or something else more generic? I think it would make sense to add this to CSSConditionRule generically, not just to CSSSupportsRule.

  4. emilio commented on Jun 7, 2022

    @emilio
    Collaborator

    MediaQueryList has .matches, maybe that's good enough?

  5. emilio commented on Jun 7, 2022

    @emilio
    Collaborator

    (as a name, I mean)

  6. emilio commented on Jun 7, 2022

    @emilio
    Collaborator

    But on CSSConditionRule it's a bit tricky, because container rules need the element as an input too, to know whether the condition matches.

  7. SebastianZ commented on Jun 8, 2022

    @SebastianZ
    ContributorAuthor

    With the changes for CSSContainerRule discussed in #7033, this can stay a simple getter because the query container is determined by the container name and query.

    Sebastian

  8. SebastianZ commented on Jun 8, 2022

    @SebastianZ
    ContributorAuthor

    matches rather refers to matching elements, though in case of CSSSupportsRule this is not the case. isTrue sounds a little too generic to me regarding the derived rules. Maybe isConditionMet or something? Anyway, I don't have a strong opinion on the name.

    Sebastian

  9. svgeesus commented on Jul 27, 2022

    @svgeesus
    Collaborator

    Maybe met?

  10. svgeesus commented on Jul 27, 2022

    @svgeesus
    Collaborator

    But regardess of naming yes, I think we should have such a getter

  11. css-meeting-bot commented on Jul 27, 2022

    @css-meeting-bot
    Member

    The CSS Working Group just discussed CSSSupportsRule should expose bool, and agreed to the following:

    • RESOLVED: Add .matches to CSSMediaRule and CSSSupportsRule
    The full IRC log of that discussion <TabAtkins> Topic: CSSSupportsRule should expose bool
    <faceless> present- (got to dash)
    <TabAtkins> github: https://github.com//issues/4240
    <astearns> ack chris
    <TabAtkins> chris: Perfectly reasonable to have a getter to know whether the condition matches
    <TabAtkins> chris: Most discussion is bikeshedding the name, not whether it shoudl exist or not
    <TabAtkins> chris: Interested if there's arguments against
    <fantasai> TabAtkins: Definitely should exist, could recreate by running it through existing APIs
    <astearns> ack dbaron
    <emilio> q+
    <TabAtkins> dbaron: agree it shoudl exist. At some point when I drafted the IDL I made a common base class for supports and media. Might not exist now, but if we make a bool like this we should make it common between the rules
    <astearns> ack fantasai
    <TabAtkins> STrong agree
    <TabAtkins> fantasai: Yeah, suggest putting it on CSSConditionRule superclass, which does exist
    <TabAtkins> fantasai: emailio pointed out it's tricky on @container rules since they rely on the element being matched as well
    <TabAtkins> fantasai: But we should have consistent naming even if it's individual methods on each subclass
    <astearns> ack emilio
    <TabAtkins> emilio: Yeah, superclass is tricky because CQs shouldn't have it
    <TabAtkins> emilio: I think the API for CQs would look a bit different, would be a function that takes an element, and it would force layout, etc
    <TabAtkins> emilio: So I think it should exist, but not on the superclass
    <TabAtkins> TabAtkins: I suggest we just define a getter on the subclasses it makes sense for, yeah
    <fantasai> ...
    <fantasai> TabAtkins: .matches works, already on MQlist
    <fantasai> TabAtkins: meaning carries over well
    <TabAtkins> emilio: fwiw, "matches" is what we use internally in Gecko
    <TabAtkins> chris: .met would work, but okay with .matches too
    <TabAtkins> fantasai: Happy to go with .matches since MQList already has it
    <chris> fine with matches
    <fantasai> s/.../fantasai: Sure, but what's it called?/
    <TabAtkins> astearns: So proposed resolution to add .matches to the relevant conditional rules
    <TabAtkins> dholbert: Q about subclasses vs superclass
    <TabAtkins> dholbert: Can we put in an intermediate superclass so it's shared?
    <fantasai> TabAtkins: IDL supports this, but it is an observable change
    <chris> emilio could you propose some IDL in the issue?
    <fantasai> TabAtkins: we thought it would be useful for ConditionalRule, but less clear if it's worth it for this
    <fantasai> astearns: Which rules are affected?
    <emilio> chris: sure, `readonly attribute boolean matches;` on the two individual rules?
    <fantasai> TabAtkins: @media and @supports
    <TabAtkins> yeah, that's the IDL
    <TabAtkins> RESOLVED: Add .matches to CSSMediaRule and CSSSupportsRule
  12. 17 remaining items

  13. svgeesus commented on Jul 17, 2024

    @svgeesus
    Collaborator

    re-tagging because the agreed edits from @fantasai are on css-conditional-3

  14. svgeesus commented on Jul 24, 2024

    @svgeesus
    Collaborator

    Missing tests collected in separate issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions