-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14321 from craftcms/feature/cms-14313-sidebar-links
Global nav subnav
- Loading branch information
Showing
14 changed files
with
303 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Very simple disclosure trigger. | ||
* | ||
* Allows you to wrap a button[type="button"] and target an element to toggle the `is-open` class on. | ||
* Set `aria-expanded` on the button | ||
*/ | ||
class CraftDisclosure extends HTMLElement { | ||
connectedCallback() { | ||
this.trigger = this.querySelector('button[type="button"]'); | ||
if (!this.trigger) { | ||
console.error(`craft-disclosure elements must include a button`, this); | ||
return; | ||
} | ||
|
||
this.target = document.getElementById( | ||
this.trigger.getAttribute('aria-controls') | ||
); | ||
if (!this.target) { | ||
console.error(`No target found for disclosure`, this.trigger); | ||
return; | ||
} | ||
|
||
if (!this.trigger.getAttribute('aria-expanded')) { | ||
this.trigger.setAttribute('aria-expanded', 'false'); | ||
} | ||
|
||
this.trigger.addEventListener('click', this.toggle.bind(this)); | ||
|
||
this.expanded = this.trigger.getAttribute('aria-expanded') === 'true'; | ||
} | ||
|
||
toggle() { | ||
if (this.expanded) { | ||
this.close(); | ||
} else { | ||
this.open(); | ||
} | ||
} | ||
|
||
open() { | ||
this.trigger.setAttribute('aria-expanded', 'true'); | ||
this.expanded = true; | ||
this.target.classList.add('is-open'); | ||
console.log('opening'); | ||
} | ||
|
||
close() { | ||
this.trigger.setAttribute('aria-expanded', 'false'); | ||
this.expanded = false; | ||
this.target.classList.remove('is-open'); | ||
console.log('closing'); | ||
} | ||
} | ||
|
||
customElements.define('craft-disclosure', CraftDisclosure); |