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

Raw text is still visible when its parent details element is closed #20

Open
emlowry opened this issue Apr 17, 2019 · 2 comments
Open

Comments

@emlowry
Copy link

emlowry commented Apr 17, 2019

I've only tested this in Edge and IE, but using this polyfill turns this:

<details open>
    <summary>Open details</summary>
    Show raw text<span> and text in elements</span>.
</details>
<details>
    <summary>Closed details</summary>
    Show raw text<span> and text in elements</span>.
</details>
Text outside the details.

into this:

▼Open details
Show raw text and text in elements.
►Closed details
Show raw text.
Text outside the details.

instead of the expected:

▼Open details
Show raw text and text in elements.
►Closed details
Text outside the details.

@javan
Copy link
Owner

javan commented Apr 30, 2019

Thanks for the report!

Showing and hiding content is implemented with CSS:

details:not([open]) > *:not(summary) {
display: none;
}

Since CSS can only target element nodes, the polyfill would need to wrap all text nodes in an element like <span> or <div>. For now, you can work around this by always using a container element. For example:

<details>
  <summary>Closed details</summary>
  <div>
    Show raw text<span> and text in elements</span>.
  </div>
</details>

@dalvarezmartinez1
Copy link

dalvarezmartinez1 commented Jul 9, 2019

@javan Thanks for the polyfill.But this will fail even without raw text. If the element(s) following the summary override the display property and their css selector has a higher specificity. Maybe !important would be a nice addition:

details:not([open]) > *:not(summary) {
display: none !important;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants