Skip to content

Commit ea3afab

Browse files
authored
fix(vue): replace legacy sr-only with amplify-visually-hidden (#2712)
* use amplify-visually-hidden over sr-only * Add alias-control unit test * Create slow-cycles-search.md * Remove describe layer and improve wording * start each `it` with a verb + remove unused code * Align wording
1 parent 15e6795 commit ea3afab

File tree

8 files changed

+99
-34
lines changed

8 files changed

+99
-34
lines changed

.changeset/slow-cycles-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui-vue": patch
3+
---
4+
5+
fix(vue): replace legacy `sr-only` with `amplify-visually-hidden`

packages/vue/global-spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import BaseWrapper from './src/components/primitives/base-wrapper.vue';
1+
import BaseAlert from './src/components/primitives/base-alert.vue';
2+
import BaseFieldSet from './src/components/primitives/base-field-set.vue';
23
import BaseFooter from './src/components/primitives/base-footer.vue';
34
import BaseForm from './src/components/primitives/base-form.vue';
4-
import BaseAlert from './src/components/primitives/base-alert.vue';
5+
import BaseHeading from './src/components/primitives/base-heading.vue';
6+
import BaseInput from './src/components/primitives/base-input.vue';
7+
import BaseLabel from './src/components/primitives/base-label.vue';
58
import BaseTwoTabItem from './src/components/primitives/base-two-tab-item.vue';
69
import BaseTwoTabs from './src/components/primitives/base-two-tabs.vue';
7-
import BaseFieldSet from './src/components/primitives/base-field-set.vue';
8-
import BaseHeading from './src/components/primitives/base-heading.vue';
10+
import BaseWrapper from './src/components/primitives/base-wrapper.vue';
911
import AmplifyButton from './src/components/primitives/amplify-button.vue';
1012

1113
export const components = {
12-
BaseWrapper,
13-
BaseFooter,
14-
BaseForm,
1514
AmplifyButton,
16-
BaseTwoTabItem,
17-
BaseTwoTabs,
1815
BaseAlert,
1916
BaseFieldSet,
17+
BaseFooter,
18+
BaseForm,
2019
BaseHeading,
20+
BaseInput,
21+
BaseLabel,
22+
BaseTwoTabItem,
23+
BaseTwoTabs,
24+
BaseWrapper,
2125
};

packages/vue/jest.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
verbose: true,
44
moduleFileExtensions: ['js', 'ts', 'json', 'vue', 'tsx'],
55
modulePathIgnorePatterns: ['<rootDir>/dist/'],
6+
setupFilesAfterEnv: ['./jest.setup.ts'],
67
transform: {
78
'^.+\\.(ts)$': 'ts-jest',
89
'^.+\\.(js|jsx)$': 'babel-jest',

packages/vue/jest.setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import '@testing-library/jest-dom';
2+
3+
/**
4+
* This is a workaround to the problem of the jsdom library not supporting
5+
* URL.createObjectURL. See https://github.com/jsdom/jsdom/issues/1721.
6+
*/
7+
if (typeof window.URL.createObjectURL === 'undefined') {
8+
window.URL.createObjectURL = jest.fn();
9+
}

packages/vue/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@rollup/plugin-dynamic-import-vars": "^1.4.0",
4949
"@rollup/plugin-typescript": "^8.2.5",
5050
"@rushstack/eslint-patch": "^1.1.3",
51+
"@testing-library/jest-dom": "^5.14.1",
5152
"@testing-library/vue": "^6.6.0",
5253
"@types/jest": "^27.0.1",
5354
"@types/node": "^17.0.34",
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import AliasControl from '../alias-control.vue';
2+
import { components } from '../../../global-spec';
3+
import { render, screen } from '@testing-library/vue';
4+
5+
describe('AliasControl', () => {
6+
it('renders a label with default class', async () => {
7+
render(AliasControl, {
8+
global: {
9+
components,
10+
},
11+
props: {
12+
label: 'Username',
13+
name: 'username',
14+
placeholder: 'Username',
15+
},
16+
});
17+
const label = await screen.findByText('Username');
18+
expect(label).toHaveClass('amplify-label');
19+
});
20+
21+
it('should add `amplify-visually-hidden` class to label when labelHidden is true', async () => {
22+
render(AliasControl, {
23+
global: {
24+
components,
25+
},
26+
props: {
27+
label: 'Username',
28+
name: 'username',
29+
placeholder: 'Username',
30+
labelHidden: true,
31+
},
32+
});
33+
34+
const label = await screen.findByText('Username');
35+
expect(label).toHaveClass('amplify-visually-hidden');
36+
});
37+
38+
it('renders text field with default class and attributes', async () => {
39+
render(AliasControl, {
40+
global: {
41+
components,
42+
},
43+
props: {
44+
label: 'Username',
45+
name: 'username',
46+
placeholder: 'Username',
47+
},
48+
});
49+
const field = await screen.findByRole('textbox');
50+
expect(field).toHaveClass('amplify-input', 'amplify-field-group__control');
51+
});
52+
53+
it('should add aria-invalid attribute to text field when hasError is true', async () => {
54+
render(AliasControl, {
55+
global: {
56+
components,
57+
},
58+
props: {
59+
label: 'Username',
60+
name: 'username',
61+
placeholder: 'Username',
62+
hasError: true,
63+
},
64+
});
65+
66+
const field = await screen.findByRole('textbox');
67+
expect(field).toHaveAttribute('aria-invalid');
68+
});
69+
});

packages/vue/src/components/alias-control.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const randomPhone = Math.floor(Math.random() * 999999);
4646
<base-label
4747
:for="'amplify-field-' + random"
4848
class="amplify-label"
49-
:class="{ 'sr-only': labelHidden }"
49+
:class="{ 'amplify-visually-hidden': labelHidden }"
5050
v-bind="$attrs"
5151
>
5252
{{ label }}

yarn.lock

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)