Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support multiple pseudo states simultaneously #9789

Copy link
Copy link
Open
@rigor789

Description

@rigor789
Issue body actions

Is your feature request related to a problem? Please describe.


Update: Looks like there are methods to manipulate pseudoStates already:

  • addPseudoClass
  • deletePseudoClass

These might be enough to cover the use-case, though a helper API to make it easier to switch would be welcome.


NativeScript supports pseudo selectors to style views based on their state. For example

Button:disabled {
 background-color: #333;
}

However it does not support multiple pseudo states simultaneously. A good example where this would be useful is a Switch/Checkbox view:

<Switch checked="true" isEnabled="false" />
Switch:checked:disabled {
 background-color: #333;
}

The above css should set the background color of the switch when it is both checked and disabled.

Describe the solution you'd like

A new API to handle multiple pseudo states simultaneously.

Right now we have the View._goToVisualState(state: string); method.

We could handle visual states in an array, or for performance reasons a flag system would work too.

// clear previous state and set it to :checked:disabled (or :disabled:checked)
this.setPseudoState(PseudoState.CHECKED | PseudoState.DISABLED);

// keep previous state and add :disabled
this.addPseudoState(PseudoState.DISABLED);

// keep previous state and remove :disabled
this.removePseudoState(PseudoState.DISABLED);

// keep previous state, but replace :disabled with :enabled
this.replacePseudoState(PseudoState.DISABLED, PseudoState.ENABLED);

The api is open for debate.

A key missing piece is support for custom PseudoState values - the API would need to consider those to be complete.

Describe alternatives you've considered

We can handle the different states with simple classes, however a pseudo based solution would be ideal.

Anything else?

This would be a killer feature for using TailwindCSS where different states can be targeted inline:

<Switch 
  class="bg-gray-200 disabled:bg-gray-50 checked:bg-blue-300 text-blue-300 disabled:text-gray-300 checked:text-green-300" 
  checked="isChecked" 
  isEnabled="isEnabled"
/>

Please accept these terms

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.