-
Notifications
You must be signed in to change notification settings - Fork 236
docs(opacity-checkerboard): enhance README with detailed usage #5751
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,29 +1,108 @@ | ||
| ## Description | ||
| ## Overview | ||
|
|
||
| The `opacity-checkerboard` class is used to highlight opacity. Leverage these styles in your component as outlined below to unify you application's visuals with those delivered by various Spectrum Web Components. | ||
| The `opacity-checkerboard` class provides a CSS utility that displays a checkerboard pattern background, commonly used to highlight transparent or semi-transparent areas in UI components. This visual indicator helps users distinguish between transparent and opaque regions, making it an essential tool for color pickers, image editors, and other components that work with opacity. | ||
|
|
||
| ## Usage | ||
| ### Usage | ||
|
|
||
| Import the styles from the `opacity-checkerboard` CSS: | ||
| [](https://www.npmjs.com/package/@spectrum-web-components/opacity-checkerboard) | ||
| [](https://bundlephobia.com/result?p=@spectrum-web-components/opacity-checkerboard) | ||
|
|
||
| ```bash | ||
| yarn add @spectrum-web-components/opacity-checkerboard | ||
| ``` | ||
|
|
||
| Import the opacity checkerboard styles from: | ||
|
|
||
| ```javascript | ||
| import opacityCheckerBoardStyles from '@spectrum-web-components/opacity-checkerboard/src/opacity-checkerboard.css.js'; | ||
| ``` | ||
|
|
||
| Add it to your component's styles array before your component's styles. The order that you include the styles in makes a difference, because selectors within opacity checkerboard may have the same | ||
| specificity as those within your component. | ||
| ### Integration | ||
|
|
||
| ```js | ||
| To integrate the opacity checkerboard styles into your component, add them to your component's styles array. The order of inclusion is important, as selectors within opacity checkerboard may have the same specificity as those within your component: | ||
|
|
||
| ```javascript | ||
| public static override get styles(): CSSResultArray { | ||
| return [opacityCheckerBoardStyles, styles]; | ||
| } | ||
| ``` | ||
|
|
||
| Use the `opacity-checkerboard` class in your component's `render()` method: | ||
| ### Examples | ||
|
|
||
| #### Basic usage | ||
|
|
||
| Apply the `opacity-checkerboard` class to any element that needs to display the checkerboard pattern: | ||
|
|
||
| ```html-live demo | ||
| <div | ||
| class="opacity-checkerboard" | ||
| style="inline-size: 100px; block-size: 100px;" | ||
| aria-label="Transparency indicator showing checkerboard pattern" | ||
| ></div> | ||
| ``` | ||
|
|
||
| #### With overlaid content | ||
|
|
||
| The opacity checkerboard works well as a background for elements with partial transparency: | ||
|
|
||
| ```html-live | ||
| <div | ||
| class="opacity-checkerboard" | ||
| style="inline-size: 200px; block-size: 200px; position: relative;" | ||
| role="img" | ||
| aria-label="Color preview with transparency" | ||
| > | ||
| <div | ||
| style=" | ||
| position: absolute; | ||
| inset: 0; | ||
| background-color: rgba(255, 0, 0, 0.5); | ||
| " | ||
| aria-label="Semi-transparent red color overlay" | ||
| ></div> | ||
| </div> | ||
| ``` | ||
|
|
||
| ### Accessibility | ||
|
|
||
| When implementing the opacity checkerboard pattern, ensure proper accessibility by: | ||
|
|
||
| - **Providing context**: Add appropriate ARIA labels to describe what the checkerboard pattern represents | ||
| - **Role attribution**: Use `role="img"` when the checkerboard serves as a visual indicator | ||
| - **Descriptive labels**: Include `aria-label` attributes that explain the purpose of the transparency indicator | ||
| - **Alternative text**: When used in color pickers or image editors, provide text alternatives that describe the transparency level | ||
|
|
||
| #### Screen reader support | ||
|
|
||
| The opacity checkerboard is a purely visual indicator. Always provide alternative text or descriptions for screen reader users: | ||
|
|
||
| ```html-live | ||
| <div | ||
| class="opacity-checkerboard" | ||
| style="inline-size: 100px; block-size: 100px;" | ||
| aria-label="Checkerboard pattern indicating transparent areas" | ||
| > | ||
| <span class="visually-hidden">Current opacity: 75%</span> | ||
| </div> | ||
| ``` | ||
|
|
||
| #### Keyboard navigation | ||
|
|
||
| When the opacity checkerboard is part of an interactive component, ensure it doesn't interfere with keyboard navigation: | ||
|
|
||
| ```html-live | ||
| <button | ||
| class="color-button" | ||
| aria-label="Select color with 50% opacity" | ||
| aria-describedby="opacity-description" | ||
| > | ||
| <span | ||
| class="opacity-checkerboard" | ||
| style="inline-size: 40px; block-size: 40px; display: block;" | ||
| ></span> | ||
| <span id="opacity-description" class="visually-hidden"> | ||
| Color preview shown over checkerboard pattern indicating 50% | ||
| transparency | ||
| </span> | ||
| </button> | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
You are trying to surface up semantic meaning to the users but you shouldn't label the checkerboard itself. You can expose that information via a text node or a live region that updates as opacity changes.
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.
Opacity Checkerboard is just a visual indicator it should remain hidden from screen readers.
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.
The opacity checkerboard is indeed just a visual pattern and shouldn't be announced to screen readers. I agree that the semantic meaning should come from the context where it's used, not the checkerboard itself. I have added
aria-hidden:truein the documentation.