Repository navigation
Open tables in a pop-up when viewed in expanded mode #11895
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
base: development
Are you sure you want to change the base?
Changes from all commits
1944cb6
a24a4d1
be6ffb6
00870e1
4d748f8
d313a53
9b30608
25f27b3
102e616
bfa8b60
5a57e18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| (function () { | ||
| 'use strict'; | ||
|
|
||
| var FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'; | ||
|
|
||
| // Makes a scroll container keyboard accessible only when it actually scrolls | ||
| function updateScrollable(el, label) { | ||
| var scrolls = el.scrollWidth > el.clientWidth || el.scrollHeight > el.clientHeight; | ||
| if (scrolls) { | ||
| el.setAttribute('tabindex', '0'); | ||
| el.setAttribute('role', 'region'); | ||
| el.setAttribute('aria-label', label); | ||
| } else { | ||
| el.removeAttribute('tabindex'); | ||
| el.removeAttribute('role'); | ||
| el.removeAttribute('aria-label'); | ||
| } | ||
| } | ||
|
|
||
| function tableLabel(wrap) { | ||
| return (wrap.dataset.title || 'Table') + ' (scrollable)'; | ||
| } | ||
|
|
||
| function init() { | ||
| document.querySelectorAll('.expandable-table-btn').forEach(function (btn) { | ||
| btn.addEventListener('click', function () { | ||
| var wrap = btn.closest('.expandable-table-wrap'); | ||
| var modal = wrap.nextElementSibling; | ||
| openModal(wrap, modal); | ||
| }); | ||
| }); | ||
|
|
||
| document.querySelectorAll('.expandable-table-wrap').forEach(function (wrap) { | ||
| var inner = wrap.querySelector('.expandable-table-inner'); | ||
| var check = function () { updateScrollable(inner, tableLabel(wrap)); }; | ||
| check(); | ||
| if (window.ResizeObserver) { | ||
| new ResizeObserver(check).observe(inner); | ||
| } else { | ||
| window.addEventListener('resize', check); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function openModal(wrap, modal) { | ||
| var title = wrap.dataset.title || ''; | ||
| modal.querySelector('.expandable-table-title').textContent = title; | ||
| if (title) modal.setAttribute('aria-label', title); | ||
|
|
||
| var body = modal.querySelector('.expandable-table-body'); | ||
| body.innerHTML = ''; | ||
| var clone = wrap.querySelector('.expandable-table-inner').cloneNode(true); | ||
| // The modal body is the scroll container, so the cloned wrapper must not be a second tab stop | ||
| clone.removeAttribute('tabindex'); | ||
| clone.removeAttribute('role'); | ||
| clone.removeAttribute('aria-label'); | ||
| body.appendChild(clone); | ||
|
|
||
| modal.removeAttribute('hidden'); | ||
| document.body.classList.add('expandable-table-open'); | ||
| updateScrollable(body, tableLabel(wrap)); | ||
|
|
||
| var closeBtn = modal.querySelector('.expandable-table-close'); | ||
| closeBtn.focus(); | ||
|
|
||
| function close() { | ||
| modal.setAttribute('hidden', ''); | ||
| document.body.classList.remove('expandable-table-open'); | ||
| btn.focus(); | ||
| modal.querySelector('.expandable-table-overlay').removeEventListener('click', close); | ||
| document.removeEventListener('keydown', onKey); | ||
| } | ||
|
|
||
| var btn = wrap.querySelector('.expandable-table-btn'); | ||
| closeBtn.onclick = close; | ||
| modal.querySelector('.expandable-table-overlay').addEventListener('click', close); | ||
|
|
||
| function onKey(e) { | ||
| if (e.key === 'Escape') { | ||
| close(); | ||
| return; | ||
| } | ||
| if (e.key !== 'Tab') return; | ||
|
|
||
| // Keep focus inside the dialog while it is open | ||
| var items = modal.querySelector('.expandable-table-dialog').querySelectorAll(FOCUSABLE); | ||
| if (!items.length) return; | ||
| var first = items[0]; | ||
| var last = items[items.length - 1]; | ||
| var active = document.activeElement; | ||
| if (!modal.contains(active)) { | ||
| e.preventDefault(); | ||
| first.focus(); | ||
| } else if (e.shiftKey && active === first) { | ||
| e.preventDefault(); | ||
| last.focus(); | ||
| } else if (!e.shiftKey && active === last) { | ||
| e.preventDefault(); | ||
| first.focus(); | ||
| } | ||
| } | ||
| document.addEventListener('keydown', onKey); | ||
| } | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', init); | ||
| } else { | ||
| init(); | ||
| } | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,53 @@ public class Hello1 | |
|
|
||
| 2. Second list item | ||
|
|
||
| ### Expandable Tables | ||
|
|
||
| Use the `expandable-table` shortcode to add an **Expand Table** button above a wide table. When readers click the button, the table opens in a window on the same page, which makes it easier to read. Place the table between the opening and closing tags, with a blank line after the opening tag and before the closing tag: | ||
|
|
||
| ```md | ||
| {{% expandable-table title="Attribute Mapping" %}} | ||
|
|
||
| | IdP Attribute | Configured Entity Attribute | | ||
| | --- | --- | | ||
| | email | Email | | ||
| | name | FullName | | ||
|
|
||
| {{% /expandable-table %}} | ||
| ``` | ||
|
Comment on lines
+115
to
+124
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might have to escape the |
||
|
|
||
| The optional `title` parameter sets the title shown at the top of the window. If you omit it or leave it blank, the window has no title. | ||
|
|
||
| Here is an example: | ||
|
|
||
| {{% expandable-table title="Attribute Mapping" %}} | ||
|
|
||
| | IdP Attribute | Configured Entity Attribute | | ||
| | --- | --- | | ||
| | email | Email | | ||
| | name | FullName | | ||
|
|
||
| {{% /expandable-table %}} | ||
|
|
||
| #### Expandable Tables in Lists | ||
|
|
||
| To use the shortcode in a list item, indent the shortcode tags and the table by four spaces, like any other content in the list item, and use the `<` delimiter instead of `%`. The shortcode removes the indentation from the table, so the table does not render as a code block: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why we would ever need to use the % delimiter for this shortcode? Outside of lists, does it provide any advantage over <?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I think it should always be the same. I think there was a discussion where people complained that it was different from other shortcodes, but there is a difference for a reason and I think we should follow the distinction in the documentation: https://gohugo.io/content-management/shortcodes/#notation
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If people can't remember, they can always put some shortcodes into their VS Code so they don't have to remember. I've got a bunch I can share. |
||
|
|
||
| ```md | ||
| 1. Review the mapping: | ||
|
|
||
| {{< expandable-table title="Attribute Mapping" >}} | ||
|
|
||
| | IdP Attribute | Configured Entity Attribute | | ||
| | --- | --- | | ||
| | email | Email | | ||
| | name | FullName | | ||
|
|
||
| {{< /expandable-table >}} | ||
|
|
||
| 2. Continue with the next step. | ||
| ``` | ||
|
|
||
| ### Images (Figures) | ||
|
|
||
| #### Image with Alt Text and Max-Width Class | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any recommendations on when we should use this shortcode? How are we defining "wide table"?