Skip to content

[css-pseudo] Please change the behavior of :focus-within #5654

@jolleekin

Description

@jolleekin

Current behavior

Matches an element that has user focus or contains an element that has user focus

Expected behavior

Matches an element that contains an element that has user focus

Reasons

  1. The current behavior overlaps with that of :focus (non-orthogonal)

  2. Consider this nested UI scenario: list view items containing nested buttons. The list view items and the nested buttons are clickable.

    • When user presses a list view item, the :active state should be applied to it
    • When user presses a nested button, the button should be styled as :active, but the list view item should not be. With the current behavior of :focus-within, this is impossible to achieve. However, if the behavior of :focus-within is changed to the expected behavior above, this can be achieved as follows
    /* User presses the list view item, not the buttons */
    list-view-item:active:not(:focus-within) {
      background-color: #0006;
    }
    
    /* User presses a nested button */
    button:active {
      background-color: #0006;
    }
  3. The current behavior can be achieved by combining :focus and :focus-within

Refercences

https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo
https://stackoverflow.com/questions/33114318/css-prevent-parent-element-getting-active-pseudoclass-when-child-element-is-cl

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