Skip to content

Commit

Permalink
Allow modal-manager to support sr-only class (#30)
Browse files Browse the repository at this point in the history
* Allow modal-manager to use screen reader only content as well, you can pass .sr-only class along with HTML while configuring ModalConfig class. Also you can pass sr-only class with slotted content as customContent
  • Loading branch information
nsharma123 authored Aug 24, 2022
1 parent 0e34033 commit 1819c18
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ Display completely custom content in the modal body, including light DOM content
const customContent = html`
Can contain any markup, including web components. Event listeners also work. Try clicking on the picture.
<div style="text-align: center">
<div class="sr-only">Visible for screen-readers only</div>
<a href="https://fillmurray.com" style="display: block">Fill Murray</a>
<img src="100x100.jpg" @click=${showBillAlert} />
</div>
`;
// customContent used to render as slotted content, it can also use .sr-only class
modalManager.showModal(config, customContent);
</script>
```
Expand All @@ -107,7 +109,7 @@ All of the config options:
const config = new ModalConfig();
config.title = 'Internet Archive';
config.subtitle = '';
config.headline = 'Thanks for your Support!';
config.headline = '<div class="sr-only">Visible for screen-readers only</div>Thanks for your Support!';
config.message = 'Thank you for supporting the Internet Archive!';
config.headerColor = '#36A483';
config.showProcessingIndicator = false;
Expand Down
2 changes: 2 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ <h3>Some Content</h3>
function showCustomContentModal() {
const config = new ModalConfig();
config.title = 'Custom Content';
config.headline = html`<span class="sr-only">Also support screen-reader only</span>`;

const someContent = html`
Can contain any markup, including web components. Event listeners also work. Try clicking on the picture.
<span class="sr-only">Also support screen-reader only</span>
<div style="text-align: center">
<a href="https://fillmurray.com" style="display: block">Fill Murray</a>
<img src="100x100.jpg" @click=${showBillAlert} />
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internetarchive/modal-manager",
"version": "0.2.6",
"version": "0.2.7",
"description": "A Modal Manager Web Component",
"repository": {
"type": "git",
Expand Down
22 changes: 22 additions & 0 deletions src/modal-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,28 @@ export class ModalTemplate extends LitElement {
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18),
0 4px 4px 0 rgba(0, 0, 0, 0.08);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
slot::slotted(.sr-only) {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
`;
}
}

0 comments on commit 1819c18

Please sign in to comment.