From aaa60fbd5b4d83f5ede5d3f98db182099af49134 Mon Sep 17 00:00:00 2001 From: Diana Nanyanzi <31903212+d-rita@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:52:54 +0300 Subject: [PATCH] feat: add aria attributes to loaders (#1449) * feat: add aria attributes to loaders - Add aria-valuenow attribute to linear loader - Add aria-label attribute to both linear and circular loaders - Add unit tests for loaders * refactor: change aria-label to use hyphen after code review Co-authored-by: Diana Nanyanzi --------- Co-authored-by: Mozafar Haider Co-authored-by: Diana Nanyanzi --- .../__tests__/circular-loader.test.js | 26 +++++++++++++++++ .../src/circular-loader/circular-loader.js | 3 ++ .../circular-loader.stories.js | 7 +++-- .../__tests__/linear-loader.test.js | 29 +++++++++++++++++++ .../loader/src/linear-loader/linear-loader.js | 4 +++ .../linear-loader/linear-loader.stories.js | 13 ++++++--- components/loader/types/index.d.ts | 2 ++ 7 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 components/loader/src/circular-loader/__tests__/circular-loader.test.js create mode 100644 components/loader/src/linear-loader/__tests__/linear-loader.test.js diff --git a/components/loader/src/circular-loader/__tests__/circular-loader.test.js b/components/loader/src/circular-loader/__tests__/circular-loader.test.js new file mode 100644 index 0000000000..bc34f5f735 --- /dev/null +++ b/components/loader/src/circular-loader/__tests__/circular-loader.test.js @@ -0,0 +1,26 @@ +import { mount } from 'enzyme' +import React from 'react' +import { CircularLoader } from '../circular-loader.js' + +describe('Circular Loader', () => { + it('renders the circular loader with aria label', () => { + const wrapper = mount( + + ) + const actual = wrapper.find({ 'data-test': 'circular-loader-test' }) + expect(actual.prop('role')).toBe('progressbar') + expect(actual.prop('aria-label')).toBe('Circular Loader') + }) + + it('renders the circular loader without aria label', () => { + const wrapper = mount( + + ) + const actual = wrapper.find({ 'data-test': 'circular-loader-test' }) + expect(actual.prop('aria-label')).toBe(undefined) + expect(actual.prop('role')).toBe('progressbar') + }) +}) diff --git a/components/loader/src/circular-loader/circular-loader.js b/components/loader/src/circular-loader/circular-loader.js index 2ede281513..a512c321ff 100644 --- a/components/loader/src/circular-loader/circular-loader.js +++ b/components/loader/src/circular-loader/circular-loader.js @@ -10,6 +10,7 @@ const CircularLoader = ({ invert, className, dataTest, + 'aria-label': ariaLabel, }) => (