Example Disclosure (Show/Hide) for Image Description
- -About This Example
-- The following example demonstrates using the Disclosure Pattern to provide a way of revealing a table of data that complements an image. -
-Similar examples include:
- -
-
-
Example
-Accessibility Features
--
-
- To help people with visual impairments identify the disclosure as interactive and make it easier to perceive that clicking either the disclosure button or its label changes the expanded state, when a pointer hovers over the button or its label, the background color changes, a border appears, and the cursor changes to a pointer. -
- - Because transparent borders are visible on some systems with operating system high contrast settings enabled, transparency cannot be used to create a visual difference between the element that is focused and other elements. - Instead of using transparency, the focused element has a thicker border and less padding. - When an element receives focus, its border changes from 0 to 2 pixels and padding is reduced by 2 pixels. - When an element loses focus, its border changes from 2 pixels to 0 and padding is increased by 2 pixels. - -
-
- To ensure the inline SVG arrow graphics in the CSS have sufficient contrast with the background when high contrast settings invert colors, the color of the arrows are synchronized with the color of the text content.
- For example, the color of the arrow is set to match the foreground color of high contrast mode text by specifying the CSS
currentcolorvalue for thestrokeandfillproperties of thepolygonelements used to draw the arrows. - If specific colors were instead used to specify thepolygonproperties, those colors would remain the same in high contrast mode, which could lead to insufficient contrast between the arrows and the background or even make the arrows invisible if the color matched the high contrast mode background.
- Note: The SVG element needs to have the CSSforced-color-adjustproperty set toautofor thecurrentcolorvalue to be updated in high contrast mode. - Some browsers do not useautofor the default value. -
-
Keyboard Support
-| Key | -Function | -
|---|---|
| - 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
-| Role | -Attribute | -Element | -Usage | -
|---|---|---|---|
| - |
- aria-controls="ID_REFERENCE"
- |
- button |
- Identifies the element controlled by the disclosure button. | -
| - |
- aria-expanded="false"
- |
-
- button
- |
-
-
|
-
| - |
- aria-expanded="true"
- |
-
- button
- |
-
-
|
-
JavaScript and CSS Source Code
--
-
- - CSS: - disclosure-img-long-description.css - -
- - JavaScript: - disclosureButton.js - -
HTML Source Code
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-