Skip to content

Commit d12be10

Browse files
committed
feat(SCSS module): Add sr-only SCSS module
1 parent cc8f679 commit d12be10

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/docs/scss_modules.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Meta, Title } from '@storybook/blocks';
2+
3+
<Meta title="Docs/SCSS Modules" />
4+
5+
<Title>SCSS Modules</Title>
6+
7+
This library comes with a set of SCSS modules that you can `@use` into your project. These do not come bundled as default, they need to be imported manually.
8+
9+
10+
## `_sr-only.scss`
11+
12+
```ts
13+
@use '@jackdomleo7/vue3-library/src/styles/modules/sr-only' as *;
14+
```
15+
16+
This module contains 2 classes that can be used to hide elements visually but keep them accessible to screen readers.
17+
18+
- `.sr-only`: Hides the element visually but keeps it accessible to screen readers.
19+
- `.sr-only--focusable`: Hides the element visually but keeps it accessible to screen readers. It will be visible when focused.
20+
21+
```html
22+
<button class="icon-only"><span class="sr-only">Close</span> &times;</button>
23+
24+
<button class="sr-only--focusable">Skip to main content</button>
25+
```

src/styles/modules/_sr-only.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This is a class to visually hide text from the UI, but will still be read by a screenreader
2+
// Use .sr-only.sr-only--focusable for elements such as a nav skip link
3+
4+
.sr-only {
5+
border: 0 !important;
6+
clip: rect(1px, 1px, 1px, 1px) !important;
7+
clip-path: inset(50%) !important;
8+
height: 1px !important;
9+
overflow: hidden !important;
10+
margin: -1px !important;
11+
padding: 0 !important;
12+
position: absolute !important;
13+
width: 1px !important;
14+
white-space: nowrap !important;
15+
16+
&--focusable {
17+
&:focus,
18+
&:focus-within,
19+
&:active {
20+
clip: auto !important;
21+
clip-path: none !important;
22+
height: auto !important;
23+
margin: auto !important;
24+
overflow: visible !important;
25+
position: static !important;
26+
width: auto !important;
27+
white-space: normal !important;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)