Skip to content

Commit ce7ed4e

Browse files
kelsSbennypowers
authored andcommitted
fix(clipboard)!: remove role attr and fix sr support
changed to use real button tag instead pf role button and tabindex 0 so that the copy functionality works with mobile screen readers. fixed broken tests and adjusted test to account for a 5 sec custom copy duration, cleaned up readme. Co-Authored-By: kelsS <[email protected]>
1 parent 60db754 commit ce7ed4e

File tree

8 files changed

+249
-117
lines changed

8 files changed

+249
-117
lines changed

.changeset/breezy-bikes-smell.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
"@patternfly/pfe-clipboard": major
3+
---
4+
5+
Update pfe-clipboard to function with mouse, keyboard, and screen reader and meet WCAG 2.1 A - AA Guidelines ✨♿
6+
7+
BREAKING CHANGE:
8+
`role="button"` and `tabindex=0` attributes must *no longer* be applied to `<pfe-clipboard>`, make sure all instances
9+
on your page are updated
10+
11+
```diff
12+
- <pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
13+
+ <pfe-clipboard></pfe-clipboard>
14+
```
15+
16+
`pfe-clipboard.spec.ts`
17+
- Updated tests based on a11y changes
18+
19+
`README.md`
20+
- Updated readme based on a11y updates
21+
22+
`pfe-clipboard.ts`
23+
- Added new state property for aria-disabled to added aria features
24+
- Added comments for changes
25+
- Updated the HTML in render() to add aria features
26+
- Cleaned up some comment typos
27+
28+
`pfe-clipboard.scss`
29+
- Added sr-only class to utilize with pfe-clipboard to improve the success message output for screen readers
30+
- Adjusted the padding and changes some ids to be classes to go with new HTML structure
31+
32+
`pfe-clipboard.html`
33+
- Removed role button and tabindex from pfe-clipboard tags because that is being set within the shadowDom now
34+
pfe-clipboard.js
35+
- Removed role button and tabindex from pfe-clipboard tags because that is being set within the shadowDom now
36+
37+
See [docs](https://patternflyelements.org/components/clipboard/) for more info

elements/pfe-clipboard/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import '@patternfly/pfe-clipboard';
2828

2929
### Default
3030
```html
31-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
31+
<pfe-clipboard></pfe-clipboard>
3232
```
3333

3434
### Copy text from an element on the page
@@ -38,51 +38,51 @@ Add a valid HTML selector to the target attribute, component will use `document.
3838
We recommend using ID's.
3939

4040
```html
41-
<pfe-clipboard role="button" tabindex="0" copy-from="#copy-me"></pfe-clipboard>
41+
<pfe-clipboard copy-from="#copy-me"></pfe-clipboard>
4242
<div id="copy-me">This text will get copied</div>
4343

44-
<pfe-clipboard role="button" tabindex="0" copy-from="body .copy-me"></pfe-clipboard>
44+
<pfe-clipboard copy-from="body .copy-me"></pfe-clipboard>
4545
<div class="copy-me">This text will get copied</div>
4646
```
4747

4848
### Copy arbitrary content
4949
Set the attribute `copy-from="property"` and set the property `contentToCopy` on the component with what should be copied.
5050
```html
5151
<!-- Markup on the page -->
52-
<pfe-clipboard role="button" tabindex="0" copy-from="property" id="copyButton"></pfe-clipboard>
52+
<pfe-clipboard copy-from="property" id="copyButton"></pfe-clipboard>
5353
```
5454
```js
5555
document.getElementById('copyButton').contentToCopy('Wakka wakka!');
5656
```
5757

5858
### Optionally hide the icon
5959
```html
60-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
60+
<pfe-clipboard no-icon></pfe-clipboard>
6161
```
6262

6363
### Override the link text
6464
```html
65-
<pfe-clipboard role="button" tabindex="0">
65+
<pfe-clipboard>
6666
<span slot="label">hey you, copy this url!</span>
6767
</pfe-clipboard>
6868
```
6969

7070
### Override the copied notification text
7171
```html
72-
<pfe-clipboard role="button" tabindex="0">
72+
<pfe-clipboard>
7373
<span slot="success">URL Copied to clipboard</span>
7474
</pfe-clipboard>
7575
```
7676
### Override the icon
7777
```html
78-
<pfe-clipboard role="button" tabindex="0">
78+
<pfe-clipboard>
7979
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
8080
</pfe-clipboard>
8181
```
8282

8383
## Override all slots
8484
```html
85-
<pfe-clipboard role="button" tabindex="0">
85+
<pfe-clipboard>
8686
<span slot="label">Copy this article URL</span>
8787
<span slot="success">URL Copied to clipboard</span>
8888
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
@@ -91,7 +91,7 @@ document.getElementById('copyButton').contentToCopy('Wakka wakka!');
9191

9292
## Specify the amount of seconds the copy success text should be visible
9393
```html
94-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
94+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
9595
```
9696

9797
### Accessibility

elements/pfe-clipboard/demo/pfe-clipboard.html

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,96 +16,104 @@
1616
<p>This element embeds a copy url button on your site.</p>
1717

1818
<h2>Clipboard</h2>
19-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
19+
<pfe-clipboard></pfe-clipboard>
2020

2121
<h2>Clipboard with no icon</h2>
22-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
22+
<pfe-clipboard no-icon></pfe-clipboard>
2323

2424
<h2>Clipboard: with custom icon</h2>
25-
<pfe-clipboard role="button" tabindex="0">
25+
<pfe-clipboard>
2626
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
2727
</pfe-clipboard>
2828

2929
<h2>Clipboard: with custom text & copying text from element</h2>
30-
<pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">
30+
<pfe-clipboard copy-from="#textToCopy">
3131
<span slot="label">This will copy the text in the text field below!</span>
3232
<span slot="success">Making some copies!</span>
3333
</pfe-clipboard>
34-
<input type="text" id="textToCopy" aria-label="This text will be copied" value="This text will be copied!!11"></input>
34+
<input type="text" id="textToCopy" aria-label="This text will be copied." value="This text will be copied!!"></input>
3535

3636
<h2>Clipboard: Copying text from property</h2>
37-
<pfe-clipboard role="button" tabindex="0" copy-from="property" id="propertyCopy">
37+
<pfe-clipboard copy-from="property" id="propertyCopy">
3838
</pfe-clipboard>
3939

4040
<h2>Clipboard: with custom success text duration.</h2>
41-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
41+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
42+
43+
<h2>Clipboard: with invalid success text duration.</h2>
44+
<p>Defaults to 4 seconds.</p>
45+
<pfe-clipboard copied-duration="-1"></pfe-clipboard>
46+
47+
<h2>Clipboard: with invalid success text duration, lower than 4 seconds</h2>
48+
<p>Defaults to 4 seconds.</p>
49+
<pfe-clipboard copied-duration="1"></pfe-clipboard>
4250
</pfe-band>
4351

4452
<pfe-band color="darkest">
4553
<p>This element embeds a copy url button on your site.</p>
4654

4755
<h2>Clipboard</h2>
48-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
56+
<pfe-clipboard></pfe-clipboard>
4957

5058
<h2>Clipboard with no icon</h2>
51-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
59+
<pfe-clipboard no-icon></pfe-clipboard>
5260

5361
<h2>Clipboard: with custom icon</h2>
54-
<pfe-clipboard role="button" tabindex="0">
62+
<pfe-clipboard>
5563
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
5664
</pfe-clipboard>
5765

5866
<h2>Clipboard: with custom text</h2>
59-
<pfe-clipboard role="button" tabindex="0">
67+
<pfe-clipboard>
6068
<span slot="label">You can totally click to copy url</span>
6169
<span slot="success">Making some copies!</span>
6270
</pfe-clipboard>
6371

6472
<h2>Clipboard: with custom success text duration.</h2>
65-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
73+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
6674
</pfe-band>
6775

6876
<pfe-band color="accent">
6977
<p>This element embeds a copy url button on your site.</p>
7078

7179
<h2>Clipboard</h2>
72-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
80+
<pfe-clipboard></pfe-clipboard>
7381

7482
<h2>Clipboard with no icon</h2>
75-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
83+
<pfe-clipboard no-icon></pfe-clipboard>
7684

7785
<h2>Clipboard: with custom icon</h2>
78-
<pfe-clipboard role="button" tabindex="0">
86+
<pfe-clipboard>
7987
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
8088
</pfe-clipboard>
8189

8290
<h2>Clipboard: with custom text</h2>
83-
<pfe-clipboard role="button" tabindex="0">
91+
<pfe-clipboard>
8492
<span slot="label">You can totally click to copy url</span>
8593
<span slot="success">Making some copies!</span>
8694
</pfe-clipboard>
8795

8896
<h2>Clipboard: with custom success text duration.</h2>
89-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
97+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
9098
</pfe-band>
9199

92100
<pfe-band color="lightest">
93101
<h2>Error cases</h2>
94102

95103
<h3>Set to copy "property", but Property doesn't exist</h3>
96-
<pfe-clipboard role="button" tabindex="0" copy-from="property">
104+
<pfe-clipboard copy-from="property">
97105
<span slot="label">Oops, I didn't set the property to be copied</span>
98106
</pfe-clipboard>
99107

100108
<h3>Set to copy a non-existent selector</h3>
101-
<pfe-clipboard role="button" tabindex="0" copy-from="#wakka-wakka">
109+
<pfe-clipboard copy-from="#wakka-wakka">
102110
<span slot="label">Oops, I didn't set a valid selector to be copied</span>
103111
</pfe-clipboard>
104112

105113
</pfe-band>
106114

107115
<pfe-band color="darkest">
108-
<pfe-clipboard role="button" tabindex="0" copy-from="property">
116+
<pfe-clipboard copy-from="property">
109117
<span slot="label">Oops, I didn't set the property to be copied</span>
110118
</pfe-clipboard>
111119
</pfe-band>

elements/pfe-clipboard/demo/pfe-clipboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const root = document.querySelector('[data-demo="pfe-clipboard"]')?.shadowRoot ?
66

77
root.getElementById('propertyCopy').contentToCopy = `
88
<h2>Clipboard: with custom text & copying text from element</h2>
9-
<pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">
9+
<pfe-clipboard copy-from="#textToCopy">
1010
<span slot="text">This will copy the text in the text field below!</span>
1111
<span slot="success">Making some copies!</span>
1212
</pfe-clipboard>
13-
<input type="text" id="textToCopy" value="This text will be copied!!11"></input>
13+
<input type="text" id="textToCopy" value="This text will be copied!!"></input>
1414
`;

elements/pfe-clipboard/docs/index.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,105 @@
11
{% renderOverview %}
2-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
2+
<pfe-clipboard></pfe-clipboard>
33
{% endrenderOverview %}
44

55
{% band header="Usage" %}
66
### Default
7-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
7+
<pfe-clipboard></pfe-clipboard>
88
```html
9-
<pfe-clipboard role="button" tabindex="0"></pfe-clipboard>
9+
<pfe-clipboard></pfe-clipboard>
1010
```
1111

1212
### Optionally hide the icon
13-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
13+
<pfe-clipboard no-icon></pfe-clipboard>
1414
```html
15-
<pfe-clipboard no-icon role="button" tabindex="0"></pfe-clipboard>
15+
<pfe-clipboard no-icon></pfe-clipboard>
1616
```
1717

1818
### Override the link text
19-
<pfe-clipboard role="button" tabindex="0">
19+
<pfe-clipboard>
2020
<span slot="label">You can copy this url</span>
2121
</pfe-clipboard>
2222

2323
```html
24-
<pfe-clipboard role="button" tabindex="0">
24+
<pfe-clipboard>
2525
<span slot="label">You can copy this url</span>
2626
</pfe-clipboard>
2727
```
2828

2929
### Copying text from element with custom button text
30-
<pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">
30+
<pfe-clipboard copy-from="#textToCopy">
3131
<span slot="label">This will copy the text in the text field below!</span>
3232
</pfe-clipboard>
3333
<input type="text" id="textToCopy" value="This text will be copied!"></input>
3434

3535
```html
36-
<pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">
36+
<pfe-clipboard copy-from="#textToCopy">
3737
<span slot="label">This will copy the text in the text field below!</span>
3838
</pfe-clipboard>
3939
<input type="text" id="textToCopy" value="This text will be copied!"></input>
4040
```
4141

4242
### Copying text from property
43-
<pfe-clipboard role="button" tabindex="0" copy-from="property" id="propertyCopy">
43+
<pfe-clipboard copy-from="property" id="propertyCopy">
4444
</pfe-clipboard>
4545
<script>
4646
window.addEventListener('load', function() {
47-
document.getElementById('propertyCopy').contentToCopy = ' <h2>Clipboard: with custom text & copying text from element</h2>\n <pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">\n <span slot="label">This will copy the text in the text field below!</span>\n <span slot="success">Making some copies!</span>\n </pfe-clipboard>\n <input type="text" id="textToCopy" value="This text will be copied!!11"></input>';
47+
document.getElementById('propertyCopy').contentToCopy = ' <h2>Clipboard: with custom text & copying text from element</h2>\n <pfe-clipboard copy-from="#textToCopy">\n <span slot="label">This will copy the text in the text field below!</span>\n <span slot="success">Making some copies!</span>\n </pfe-clipboard>\n <input type="text" id="textToCopy" value="This text will be copied!!"></input>';
4848
})
4949
</script>
5050

5151
```html
52-
<pfe-clipboard role="button" tabindex="0" copy-from="property" id="propertyCopy">
52+
<pfe-clipboard copy-from="property" id="propertyCopy">
5353
</pfe-clipboard>
5454
<script>
5555
window.addEventListener('load', function() {
56-
document.getElementById('propertyCopy').contentToCopy = ' <h2>Clipboard: with custom text & copying text from element</h2>\n <pfe-clipboard role="button" tabindex="0" copy-from="#textToCopy">\n <span slot="label">This will copy the text in the text field below!</span>\n <span slot="success">Making some copies!</span>\n </pfe-clipboard>\n <input type="text" id="textToCopy" value="This text will be copied!!11"></input>';
56+
document.getElementById('propertyCopy').contentToCopy = ' <h2>Clipboard: with custom text & copying text from element</h2>\n <pfe-clipboard copy-from="#textToCopy">\n <span slot="label">This will copy the text in the text field below!</span>\n <span slot="success">Making some copies!</span>\n </pfe-clipboard>\n <input type="text" id="textToCopy" value="This text will be copied!!"></input>';
5757
})
5858
</script>
5959
```
6060

6161
### Override the copied notification text
62-
<pfe-clipboard role="button" tabindex="0">
62+
<pfe-clipboard>
6363
<span slot="success">URL Copied to clipboard</span>
6464
</pfe-clipboard>
6565

6666
```html
67-
<pfe-clipboard role="button" tabindex="0">
67+
<pfe-clipboard>
6868
<span slot="success">URL Copied to clipboard</span>
6969
</pfe-clipboard>
7070
```
7171

7272
### Override the icon
73-
<pfe-clipboard role="button" tabindex="0">
73+
<pfe-clipboard>
7474
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
7575
</pfe-clipboard>
7676

7777
```html
78-
<pfe-clipboard role="button" tabindex="0">
78+
<pfe-clipboard>
7979
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
8080
</pfe-clipboard>
8181
```
8282

8383
### Override all slots
84-
<pfe-clipboard role="button" tabindex="0">
84+
<pfe-clipboard>
8585
<span slot="label">Copy this article URL</span>
8686
<span slot="success">URL Copied to clipboard</span>
8787
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
8888
</pfe-clipboard>
8989

9090
```html
91-
<pfe-clipboard role="button" tabindex="0">
91+
<pfe-clipboard>
9292
<span slot="label">Copy this article URL</span>
9393
<span slot="success">URL Copied to clipboard</span>
9494
<pfe-icon slot="icon" icon="web-icon-globe"></pfe-icon>
9595
</pfe-clipboard>
9696
```
9797

9898
### Specify the amount of seconds the copy success text should be visible
99-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
99+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
100100

101101
```html
102-
<pfe-clipboard role="button" tabindex="0" copied-duration="5"></pfe-clipboard>
102+
<pfe-clipboard copied-duration="5"></pfe-clipboard>
103103
```
104104
{% endband %}
105105

0 commit comments

Comments
 (0)