diff --git a/examples/disclosure/css/disclosure-faq.css b/examples/disclosure/css/disclosure-faq.css new file mode 100644 index 0000000000..3a0d71d55c --- /dev/null +++ b/examples/disclosure/css/disclosure-faq.css @@ -0,0 +1,38 @@ +[role="button"]:hover, +[role="button"]:focus { + background-color: #eee; + text-decoration: underline; +} + +[role="button"]:active { + background-color: #bbb; +} + +[role="button"][aria-expanded="false"]:before { + content: "\0025BA \0000A0"; + color: #630; + +} + +[role="button"][aria-expanded="true"]:before { + content: "\0025BC \0000A0"; + color: #630; +} + +dl.faq dt { + margin: 0; + padding: 0; + margin-top: 0.5em; + font-weight: bold; + font-size: 110%; +} + + +dl.faq dd { + margin: 0; + padding: 0; + margin-top: 0.25em; + margin-left: 1.5em; + font-size: 110%; + display: none; +} diff --git a/examples/disclosure/css/disclosure-img-long-description.css b/examples/disclosure/css/disclosure-img-long-description.css new file mode 100644 index 0000000000..bde8f35205 --- /dev/null +++ b/examples/disclosure/css/disclosure-img-long-description.css @@ -0,0 +1,19 @@ +[role="button"]:hover, +[role="button"]:focus { + background-color: #eee; + text-decoration: underline; +} + +[role="button"]:active { + background-color: #bbb; +} + +[role="button"][aria-expanded="false"]:before { + content: "\0025BA"; + color: #630; +} + +[role="button"][aria-expanded="true"]:before { + content: "\0025BC"; + color: #630; +} diff --git a/examples/disclosure/disclosure-faq.html b/examples/disclosure/disclosure-faq.html new file mode 100644 index 0000000000..a5ef92ec0c --- /dev/null +++ b/examples/disclosure/disclosure-faq.html @@ -0,0 +1,239 @@ + + + + +Disclosure (Show/Hide) of Answers to Frequently Asked Questions | WAI-ARIA Authoring + Practices 1.1 + + + + + + + + + + +
+

Disclosure (Show/Hide) of Answers to Frequently Asked Questions

+

+ Please provide feedback on this example in + issue 265. +

+

+ The following example demonstrates using the + disclosure design pattern + to create a set of frequently asked questions where the answers may be independently shown or hidden. +

+

Similar examples include:

+ +
+

Example

+ +
+
+ +
Park at the nearest available parking meter without paying the meter + and call 999-999-9999 to report the problem. We will note and approve your alternate + location and will investigate the cause of the shortage in your assigned facility.
+ + +
You should come to the Parking office and report the loss. There is + a fee to replace your lost permit. However, if your permit was stolen, a copy of a police + report needs to be submitted along with a stolen parking permit form for a fee replacement + exemption.
+ + +
All facilities are restricted from 2:00 am - 6:00 am on all days. No + exceptions are made for any holiday or recess except those officially listed as a + ”Holidays” in the calendar. Please note: 24-hour rental spaces, 24-hour rental lots, and + disabled parking is enforced at all times.
+ + +
Some parking facility restrictions differ from others. Be sure to + take note of the signs at each lot entrance.
+ +
+
+ +
+
+

Keyboard Support

+ + + + + + + + + + + + + + + + + +
KeyFunction
+ Tab + + Moves keyboard focus to the disclosure button. +
+ Space or
+ Enter +
+
  • + Activates the disclosure button, + which toggles the visibility of the answer to the question. +
  • +
    + +
    +

    Role, Property, State, and Tabindex Attributes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    RoleAttributeElementUsage
    + button + + span + + Identifies the span element as a button. +
    + tabindex="0" + + span + + Includes the span element in the tab sequence of the page. +
    + aria-controls="IDREF" + + span + + The disclosure button controls visibility of the container identified by the IDREF value. +
    + aria-expanded="false" + + span + +
      +
    • + Indicates that the container controlled by the disclosure button is hidden . +
    • +
    • + CSS attribute selectors (e.g. [aria-expanded="false"]) are + used to synchronize the visual states with the value of the aria-expanded + attribute. +
    • +
    • + The visual indicator of the show/hide state is created using the CSS :before pseudo selector and the content property + so the image is reliably rendered in high contrast mode of operating systems and browsers. +
    • +
    +
    + aria-expanded="true" + + span + +
      +
    • + Indicates that the container controlled by the disclosure button is visible. +
    • +
    • + CSS attribute selectors (e.g. [aria-expanded="true"]) are + used to synchronize the visual states with the value of the aria-expanded + attribute. +
    • +
    • + The visual indicator of the show/hide state is created using the CSS :before pseudo selector and the content property + so the image is reliably rendered in high contrast mode of operating systems and browsers. +
    • +
    +
    +
    + +
    +

    Javascript and CSS Source Code

    + + +
    + +
    +

    HTML Source Code

    + +
    + + +
    +
    + + + diff --git a/examples/disclosure/disclosure-img-long-description.html b/examples/disclosure/disclosure-img-long-description.html new file mode 100644 index 0000000000..1a1f0b5d4e --- /dev/null +++ b/examples/disclosure/disclosure-img-long-description.html @@ -0,0 +1,389 @@ + + + + +Disclosure (Show/Hide) of Image Description | WAI-ARIA Authoring Practices 1.1 + + + + + + + + + + +
    +

    Disclosure (Show/Hide) of Image Description

    +

    + Please provide feedback on this example in + issue 264. +

    +

    + The following example demonstrates using the + disclosure design pattern + to provide a way of revealing a table of data that complements an image. +

    +

    Similar examples include:

    + +
    +

    Example

    + +
    +

    + + Charles Minard's 1869 chart showing the number of men in + Napoleon’s 1812 Russian campaign army, their movements, as well as the temperature they + encountered on the return path + ( chart details ). +

    +
    +

    Data for Charles Minars's Chart of Naploean's Invasion of Russia

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    LocationApproximate DateSize of ArmyTempature CTempature FDirection
    Kowno RiverJune 24th442,000nanaAdvance
    WilnaJune 30th400,000nanaAdvance
    Witebskna175,000nanaAdvance
    SmolenskAugust 16th145,000nanaAdvance
    Chjatna127,000nanaAdvance
    MojaiskSeptember 7th100,000nanaAdvance
    MoscowSeptember 14th100,000nanaAdvance
    Malo-jarosewliOctober 18th96,000032Retreat
    MojaiskOctober 24th87,000032Retreat
    Wirmana55,000nanaRetreat
    SmolenskNovember 14th37,000-26-13Retreat
    Orschana24,000nanaRetreat
    Botrna20,000-14-7Retreat
    Studienska (reinforcements arrive)December 1st50,000-25-13Retreat
    MinskDecember 1st28,000-30-22Retreat
    MolodernoDecember 6th28,000-38-34Retreat
    SmorgeniDecember 7th12,000-33-27Retreat
    Wilna + + na + + 8,000nanaRetreat
    Kowno (reinforcements arrive)December 14th10,000nanaRetreat
    +
    +
    + +
    + +
    +

    Keyboard Support

    + + + + + + + + + + + + + + + + + +
    KeyFunction
    + Tab + + Moves keyboard focus to the disclosure button. +
    + Space or
    + Enter +
    +
  • + Activates the disclosure button, + which toggles the visibility of the long description. +
  • +
    + +
    +

    Role, Property, State, and Tabindex Attributes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    RoleAttributeElementUsage
    + button + + span + + Identifies the span element as a button. +
    + tabindex="0" + + span + + Includes the span element in the tab sequence of the page. +
    + aria-controls="IDREF" + + span + + The disclosure button controls visibility of the container identified by the IDREF value. +
    + aria-expanded="false" + + span + +
      +
    • + Indicates that the container controlled by the disclosure button is hidden . +
    • +
    • + CSS attribute selectors (e.g. [aria-expanded="false"]) are + used to synchronize the visual states with the value of the aria-expanded + attribute. +
    • +
    • + The visual indicator of the show/hide state is created using the CSS :before pseudo selector and the content property + so the image is reliably rendered in high contrast mode of operating systems and browsers. +
    • +
    +
    + aria-expanded="true" + + span + +
      +
    • + Indicates that the container controlled by the disclosure button is visible. +
    • +
    • + CSS attribute selectors (e.g. [aria-expanded="true"]) are + used to synchronize the visual states with the value of the aria-expanded + attribute. +
    • +
    • + The visual indicator of the show/hide state is created using the CSS :before pseudo selector and the content property + so the image is reliably rendered in high contrast mode of operating systems and browsers. +
    • +
    +
    +
    + +
    +

    Javascript and CSS Source Code

    + +
    + +
    +

    HTML Source Code

    + +
    + + + +
    +
    + + + diff --git a/examples/disclosure/images/minard.png b/examples/disclosure/images/minard.png new file mode 100644 index 0000000000..82901efbd2 Binary files /dev/null and b/examples/disclosure/images/minard.png differ diff --git a/examples/disclosure/js/disclosureButton.js b/examples/disclosure/js/disclosureButton.js new file mode 100644 index 0000000000..571451d0e2 --- /dev/null +++ b/examples/disclosure/js/disclosureButton.js @@ -0,0 +1,125 @@ +/* +* This content is licensed according to the W3C Software License at +* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document +* +* File: ButtonExpand.js +* +* Desc: Checkbox widget that implements ARIA Authoring Practices +* for a menu of links +* +* Author: Jon Gunderson and Nicholas Hoyt +*/ + +/* +* @constructor ButtonExpand +* +* +*/ +var ButtonExpand = function (domNode) { + + this.domNode = domNode; + + this.keyCode = Object.freeze({ + 'RETURN' : 13, + 'SPACE' : 32 + }); +}; + +ButtonExpand.prototype.init = function () { + + this.domNode.tabIndex = 0; + this.controlledNode = false; + + var id = this.domNode.getAttribute('aria-controls'); + + + if (id) { + this.controlledNode = document.getElementById(id); + } + + this.domNode.setAttribute('aria-expanded', 'false'); + this.hideContent(); + + this.domNode.addEventListener('keydown', this.handleKeydown.bind(this)); + this.domNode.addEventListener('click', this.handleClick.bind(this)); + this.domNode.addEventListener('focus', this.handleFocus.bind(this)); + this.domNode.addEventListener('blur', this.handleBlur.bind(this)); + +}; + +ButtonExpand.prototype.showContent = function () { + + if (this.controlledNode) { + this.controlledNode.style.display = "block"; + } + +}; + +ButtonExpand.prototype.hideContent = function () { + + if (this.controlledNode) { + this.controlledNode.style.display = "none"; + } + +}; + +ButtonExpand.prototype.toggleExpand = function () { + + if (this.domNode.getAttribute('aria-expanded') === 'true') { + this.domNode.setAttribute('aria-expanded', 'false'); + this.hideContent(); + } + else { + this.domNode.setAttribute('aria-expanded', 'true'); + this.showContent(); + } + +}; + +/* EVENT HANDLERS */ + +ButtonExpand.prototype.handleKeydown = function (event) { + + console.log("[keydown]"); + + switch (event.keyCode) { + + case this.keyCode.RETURN: + case this.keyCode.SPACE: + + this.toggleExpand(); + + event.stopPropagation(); + event.preventDefault(); + break; + + default: + break; + } + +}; + +ButtonExpand.prototype.handleClick = function (event) { + this.toggleExpand(); +}; + +ButtonExpand.prototype.handleFocus = function (event) { + this.domNode.classList.add('focus'); +}; + +ButtonExpand.prototype.handleBlur = function (event) { + this.domNode.classList.remove('focus'); +}; + +/* Initialize Hide/Show Buttons */ + +window.addEventListener('load', function(event) { + + var buttons = document.querySelectorAll("[role=button][aria-expanded][aria-controls]"); + + for(var i=0; i < buttons.length; i++) { + var be = new ButtonExpand(buttons[i]); + be.init(); + } + +}, false);