Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 69 additions & 31 deletions templates/docs/examples/patterns/code-snippet/_dropdown-multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,110 @@
<h5 class="p-code-snippet__title">Installing Thunderbird as a snap</h5>

<div class="p-code-snippet__dropdowns">
<select class="p-code-snippet__dropdown" name="menu1-select" id="menu1-select">
<option value="">amd64</option>
<option value="">i386</option>
<select class="p-code-snippet__dropdown" name="track-select-1" id="track-select-1" aria-label="Track">
<option value="latest-track-1">latest</option>
<option value="esr-track-1">esr</option>
<option value="monthly-track-1">monthly</option>
</select>

<select class="p-code-snippet__dropdown" name="menu2-select" id="menu2-select">
<option value="stable-panel">stable</option>
<option value="beta-panel">beta</option>
<option value="edge-panel">edge</option>
<select class="p-code-snippet__dropdown" name="latest-track-1" id="latest-track-1" aria-label="Channel">
<option value="latest-stable-1">stable</option>
<option value="latest-candidate-1">candidate</option>
</select>

<select class="p-code-snippet__dropdown u-hide" name="esr-track-1" id="esr-track-1" aria-hidden="true" aria-label="Channel">
<option value="esr-stable-1">stable</option>
<option value="esr-candidate-1">candidate</option>
</select>

<select class="p-code-snippet__dropdown u-hide" name="monthly-track-1" id="monthly-track-1" aria-hidden="true" aria-label="Channel">
<option value="monthly-beta-1">beta</option>
<option value="monthly-candidate-1">candidate</option>
</select>
</div>
</div>

<pre id="stable-panel" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird</code></pre>
<pre id="latest-stable-1" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird --channel=latest/stable</code></pre>

<pre id="latest-candidate-1" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=latest/candidate</code></pre>

<pre id="beta-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --beta</code></pre>
<pre id="esr-stable-1" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=esr/stable</code></pre>

<pre id="edge-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --edge</code></pre>
<pre id="esr-candidate-1" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=esr/candidate</code></pre>

<pre id="monthly-beta-1" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=monthly/beta</code></pre>

<pre id="monthly-candidate-1" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=monthly/candidate</code></pre>
</div>

<div class="p-code-snippet">
<div class="p-code-snippet__header">
<div class="p-code-snippet__dropdowns">
<select class="p-code-snippet__dropdown" name="menu1-select" id="menu1-select">
<option value="">amd64</option>
<option value="">i386</option>
<select class="p-code-snippet__dropdown" name="track-select-2" id="track-select-2" aria-label="Track">
<option value="latest-track-2">latest</option>
<option value="esr-track-2">esr</option>
<option value="monthly-track-2">monthly</option>
</select>

<select class="p-code-snippet__dropdown" name="latest-track-2" id="latest-track-2" aria-label="Channel">
<option value="latest-stable-2">stable</option>
<option value="latest-candidate-2">candidate</option>
</select>

<select class="p-code-snippet__dropdown" name="menu2-select" id="menu2-select">
<option value="headerless-stable-panel">stable</option>
<option value="headerless-beta-panel">beta</option>
<option value="headerless-edge-panel">edge</option>
<select class="p-code-snippet__dropdown u-hide" name="esr-track-2" id="esr-track-2" aria-hidden="true" aria-label="Channel">
<option value="esr-stable-2">stable</option>
<option value="esr-candidate-2">candidate</option>
</select>

<select class="p-code-snippet__dropdown u-hide" name="monthly-track-2" id="monthly-track-2" aria-hidden="true" aria-label="Channel">
<option value="monthly-beta-2">beta</option>
<option value="monthly-candidate-2">candidate</option>
</select>
</div>
</div>

<pre id="headerless-stable-panel" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird</code></pre>
<pre id="latest-stable-2" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird --channel=latest/stable</code></pre>

<pre id="latest-candidate-2" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=latest/candidate</code></pre>

<pre id="esr-stable-2" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=esr/stable</code></pre>

<pre id="headerless-beta-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --beta</code></pre>
<pre id="esr-candidate-2" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=esr/candidate</code></pre>

<pre id="headerless-edge-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --edge</code></pre>
<pre id="monthly-beta-2" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=monthly/beta</code></pre>

<pre id="monthly-candidate-2" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=monthly/candidate</code></pre>
</div>

<div class="p-code-snippet">
<div class="p-code-snippet__header is-stacked">
<h5 class="p-code-snippet__title">Installing Thunderbird as a snap on different architectures via the command line</h5>
<h5 class="p-code-snippet__title">Installing Thunderbird as a snap on different tracks via the command line</h5>

<div class="p-code-snippet__dropdowns">
<select class="p-code-snippet__dropdown" name="menu3-select" id="menu3-select">
<option value="">amd64</option>
<option value="">i386</option>
<select class="p-code-snippet__dropdown" name="track-select-3" id="track-select-3" aria-label="Track">
<option value="latest-track-3">latest</option>
<option value="esr-track-3">esr</option>
</select>

<select class="p-code-snippet__dropdown" name="latest-track-3" id="latest-track-3" aria-label="Channel">
<option value="latest-stable-3">stable</option>
<option value="latest-beta-3">beta</option>
<option value="latest-candidate-3">candidate</option>
</select>

<select class="p-code-snippet__dropdown" name="menu4-select" id="menu4-select">
<option value="stacked-stable-panel">stable</option>
<option value="stacked-beta-panel">beta</option>
<option value="stacked-edge-panel">edge</option>
<select class="p-code-snippet__dropdown u-hide" name="esr-track-3" id="esr-track-3" aria-hidden="true" aria-label="Channel">
<option value="esr-edge-3">edge</option>
</select>
</div>
</div>

<pre id="stacked-stable-panel" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird</code></pre>
<pre id="latest-stable-3" class="p-code-snippet__block--icon"><code>sudo snap install thunderbird --channel=latest/stable</code></pre>

<pre id="latest-candidate-3" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=latest/candidate</code></pre>

<pre id="stacked-beta-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --beta</code></pre>
<pre id="latest-beta-3" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=latest/beta</code></pre>

<pre id="stacked-edge-panel" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --edge</code></pre>
<pre id="esr-edge-3" class="p-code-snippet__block--icon u-hide" aria-hidden="true"><code>sudo snap install thunderbird --channel=esr/edge</code></pre>
</div>

<script>
Expand Down
38 changes: 35 additions & 3 deletions templates/docs/examples/patterns/code-snippet/_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,37 @@ function attachDropdownEvents(dropdown) {
var targetElement = document.getElementById(e.target.value);

if (targetElement) {
toggleElement(targetElement, dropdown.options);
// Check if target is another dropdown (cascading dropdowns)
if (targetElement.tagName === 'SELECT') {
// Find the container with all dropdowns
var container = dropdown.closest('.p-code-snippet__dropdowns');

// Hide all panels from all code snippet dropdowns in this group
var allChannelDropdowns = container.querySelectorAll('.p-code-snippet__dropdown');
allChannelDropdowns.forEach(function (channelDropdown) {
for (var i = 0; i < channelDropdown.options.length; i++) {
var panel = document.getElementById(channelDropdown.options[i].value);
if (panel && panel.tagName !== 'SELECT') {
panel.classList.add('u-hide');
panel.setAttribute('aria-hidden', true);
}
}
});

// Toggle between channel dropdowns
toggleElement(targetElement, dropdown.options);

// Show the panel for the newly visible dropdown's selected option
var panelId = targetElement.value;
var panelElement = document.getElementById(panelId);
if (panelElement && panelElement.tagName !== 'SELECT') {
panelElement.classList.remove('u-hide');
panelElement.setAttribute('aria-hidden', false);
}
} else {
// Target is a code panel
toggleElement(targetElement, dropdown.options);
}
}
});
}
Expand All @@ -21,8 +51,10 @@ function attachDropdownEvents(dropdown) {
function toggleElement(targetElement, options) {
for (var i = 0; i < options.length; i++) {
var element = document.getElementById(options[i].value);
element.classList.add('u-hide');
element.setAttribute('aria-hidden', true);
if (element) {
element.classList.add('u-hide');
element.setAttribute('aria-hidden', true);
}
}

targetElement.classList.remove('u-hide');
Expand Down