Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for :open pseudo-class #37869

Merged
merged 11 commits into from
Feb 4, 2025
Merged

Conversation

chrisdavidmills
Copy link
Contributor

Description

This PR documents the :open pseudo-class, which is now supported in Chrome 133: see the ChromeStatus entry.

Specifically, I have:

  • Added a page for :open, and linked that page from appropriate places
  • Updated a couple of examples to use :open instead of e.g. dialog[open]
  • Added information about using x[open] as a fallback if :open is not supported.

:open has already been added to BCD.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested review from a team as code owners January 29, 2025 18:11
@chrisdavidmills chrisdavidmills requested review from estelle and removed request for a team January 29, 2025 18:11
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs Content:HTML Hypertext Markup Language docs size/m [PR only] 51-500 LoC changed labels Jan 29, 2025
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot added the merge conflicts 🚧 [PR only] label Jan 29, 2025
@github-actions github-actions bot removed the merge conflicts 🚧 [PR only] label Jan 30, 2025
Copy link
Contributor

github-actions bot commented Jan 30, 2025

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example for :open needs to be updated. The current example is something we definitely don't want people to do in production.

files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/css/_colon_open/index.md Outdated Show resolved Hide resolved
files/en-us/web/html/element/details/index.md Outdated Show resolved Hide resolved
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an example we can use based on your example. See https://codepen.io/estelle/pen/QwLRvgW

plus one other suggestion.


Note that the open and closed states are semantic states, and don't necessary correlate with the visibility of the element in question. For example, a `<details>` element that is expanded to show its content is open, and will be selected by the `details:open` selector, even if it is hidden with a {{cssxref("visibility")}} value of `hidden`.

{{domxref("Popover API", "Popover", "", "nocode")}} elements (that is, elements with the [`popover`](/en-US/docs/Web/HTML/Global_attributes/popover) attribute set on them) have distinct semantic states representing popovers that are showing or hidden, which can coexist alongside open and closed states. You can't use the `:open` pseudo-class to target styles at popovers that are in the showing state — instead, you need to use the {{cssxref(":popover-open")}} pseudo-class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{domxref("Popover API", "Popover", "", "nocode")}} elements (that is, elements with the [`popover`](/en-US/docs/Web/HTML/Global_attributes/popover) attribute set on them) have distinct semantic states representing popovers that are showing or hidden, which can coexist alongside open and closed states. You can't use the `:open` pseudo-class to target styles at popovers that are in the showing state — instead, you need to use the {{cssxref(":popover-open")}} pseudo-class.
{{domxref("Popover API", "Popover", "", "nocode")}} elements (that is, elements with the [`popover`](/en-US/docs/Web/HTML/Global_attributes/popover) attribute set on them) have distinct semantic states representing popovers that are showing or hidden, which can coexist alongside open and closed states. To target a popover element in an open state, use the {{cssxref(":popover-open")}} pseudo-class instead.

Copy link
Contributor Author

@chrisdavidmills chrisdavidmills Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I've used your text, except that I've changed "open state" to "showing state". The official term for a popover's open state is showing, and that is the language used throughout the popover docs, even the :popover-open page. Might have been better to call the pseudo :popover-showing, but hey ho.

position: relative;
}

.select-wrapper::after {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this arrow feels clickable, but isn't.

https://codepen.io/estelle/pen/QwLRvgW?editors=1100

the linked example includes a changing arrow, and doesn't require a repaint (the border is always there, but transparent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — I was struggling with this example, and you really helped me out.

I've used your example verbatim, except that I've made the SVG arrows smaller (they were a bit big and clunky).

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! 🎉

@estelle estelle merged commit 41f2977 into mdn:main Feb 4, 2025
8 checks passed
@chrisdavidmills chrisdavidmills deleted the open-pseudo-class branch February 5, 2025 10:42
@chrisdavidmills
Copy link
Contributor Author

Super, cheers @estelle! 🫶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs Content:HTML Hypertext Markup Language docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants