Skip to content

Managing states with CustomStateSet #1110

@Westbrook

Description

@Westbrook

Currently when wanting to add/delete a CSS Custom State to the CustomStateSet you need to do something like the following:

if (value) {
    this.internals.states.add(state);
} else {
   this.internals.states.delete(state);
}

When a custom element sets out to manage this state once, this is not too big of a deal, however as an author looks to manage this state from more locations you end up wanting for a helper method to support managing this:

setState(state, value) {
    if (value) {
        this.internals.states.add(state);
    } else {
       this.internals.states.delete(state);
    }
}

It's not the most complicated boilerplate required by the various Web Components APIs, but it's an added bit of complexity for authors to spend limited decisions making faculties on. Was there a specific reason not to include a toggle(state, value) method? With this we'd be able to simplify this usage to:

this.internals.states.toggle(state, value);

Would there be room to include such an expansion on the CustomStateSet object?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions