Skip to content

Conversation

choldgraf
Copy link
Member

@choldgraf choldgraf commented Feb 4, 2022

This updates our CSS to make the toggle buttons have more reasonable defaults when hiding. Here is the logic we follow:

  • Any toggle buttons with hidden content will not show up in the printed page.
  • Any toggle buttons with shown content will show their content, but not the toggle buttons themselves.

UPDATE: The latest commit updates the behavior to the following:

  • When print happens, a little JS is triggered to search for any closed details toggles, and any closed .admonition toggles
  • It opens them, and stores a data attribute to note that they've been opened for print
  • After print, it re-searches for these elements again, closes them, and deletes the data attribute
  • This is configurable by a new config option togglebutton_open_on_print (default True)

closes #14

@akhmerov
Copy link

akhmerov commented Feb 4, 2022

I might be misunderstanding, but I'm not sure it's always desirable to hide content in the printed page. A frequent use of collapsed content is "something that you may want to read but not very high priority". In a printed page the reader isn't given a choice, and therefore not showing that content may lead to them missing information. I see, it's tracked in #14.

@choldgraf
Copy link
Member Author

choldgraf commented Feb 4, 2022

Yeah I agree - this PR just makes the behavior consistent between the two types of toggle content. It will be more complicated to get the details tags opened for printing - so maybe that's a future improvement to make. In the meantime, it seemed like the default behavior should be to hide both. Does that make sense?

I guess our other option would be "hide the toggle button directive, but not the admonitions". So which makes the most sense:

  1. Hide both kinds of elements (both the toggle admonitions, and the toggle button content) for now
  2. Only hide the button content, but open up the admonitions.

I think either way it makes sense to hide the button UI elements

@choldgraf
Copy link
Member Author

On reflection, since #14 suggests that most would want content shown on print by default, I'll take the low hanging fruit and add that in for admonitions here, and we can do the toggle button content later

@choldgraf
Copy link
Member Author

ok @akhmerov you nerd-sniped me 😅

The latest commit updates the behavior to the following:

  • When print happens, a little JS is triggered to search for any closed details toggles, and any closed .admonition toggles
  • It opens them, and stores a data attribute to note that they've been opened for print
  • After print, it re-searches for these elements again, closes them, and deletes the data attribute
  • This is configurable by a new config option togglebutton_open_on_print (default True)

I think that should nail down this behavior

@akhmerov
Copy link

akhmerov commented Feb 5, 2022

Haha, this is awesome! Not sure if a configurable is worth: I would propose to make the implemented behavior default and see if anyone requests an ability to turn it off.

@choldgraf
Copy link
Member Author

Yeah fair enough - though it was really simple to implement, just a quick if check 🤷

@choldgraf choldgraf changed the title Improve hiding behavior for togglebuttons ENHANCE: Improve hiding behavior for togglebuttons Feb 5, 2022
@choldgraf choldgraf merged commit 9e73e2e into master Feb 5, 2022
@choldgraf choldgraf deleted the hidden branch February 5, 2022 17:58
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

Successfully merging this pull request may close these issues.

Open toggle buttons when printing
2 participants