Skip to content

Commit

Permalink
test(accessibility-checker): update to versioned ruleArchive (#17351)
Browse files Browse the repository at this point in the history
* test(accessibility-checker): update to versioned ruleset

* chore(accessibility-checker): update to 3.1.75

* chore(accessibility-checker): update to 3.1.75

* fix(inputprops): remove autoComplete property

* chore(deps): update to latest accessibility-checker

* add dep cache

* revert unintended file changes

* revert unintended file changes

* chore: yarn dedupe

* chore: update accessibility-checker to 3.1.77

* chore: fix a11y violations

* chore: wip

* fix: updated test, snapshots, yarn format

* chore: yarn format

* test: updated tests to match ariaLabelText

* chore(accessibility-checker): update to 3.1.78

* chore: adds cache

* refactor: added rules to denylist

* refactor: added rules to denylist

* chore: yarn dedupe

* chore: nx cache

* chore: removes .nx/cache files

* test: adds tests for SliderSkeleton

* refactor: revert scss change

---------

Co-authored-by: Nikhil Tomar <[email protected]>
Co-authored-by: Nikhil Tomar <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 181f38f commit 812d029
Show file tree
Hide file tree
Showing 54 changed files with 339 additions and 249 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 10 additions & 8 deletions achecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
const path = require('path');

module.exports = {
ruleArchive: '17June2024',
ruleArchive: 'versioned',
policies: ['Custom_Ruleset'],
failLevels: ['violation'],
reportLevels: [
'violation',
'potentialviolation',
'recommendation',
'potentialrecommendation',
'manual',
],
reportLevels: !process.env.CI
? ['violation']
: [
'violation',
'potentialviolation',
'recommendation',
'potentialrecommendation',
'manual',
],
outputFormat: ['json'],
outputFolder: path.join('.avt', 'reports'),
baselineFolder: path.join('.avt', 'baseline'),
Expand Down
3 changes: 3 additions & 0 deletions config/jest-config-carbon/matchers/toHaveNoACViolations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ async function toHaveNoACViolations(node, label) {
'html_skipnav_exists',
'aria_content_in_landmark',
'aria_child_tabbable',
'aria_attribute_conflict',
'label_name_visible',
'target_spacing_sufficient',
]);
const ruleset = await aChecker.getRuleset('IBM_Accessibility');
const customRuleset = JSON.parse(JSON.stringify(ruleset));
Expand Down
2 changes: 1 addition & 1 deletion config/jest-config-carbon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/runtime": "^7.24.7",
"accessibility-checker": "^3.1.74",
"accessibility-checker": "^3.1.78",
"axe-core": "^4.3.5",
"babel-jest": "^28.1.0",
"chalk": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion e2e/components/AILabel/AILabel-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test.describe('@avt AILabel', () => {
},
});
const slug = page.getByRole('button', {
name: 'AI - Show information',
name: 'AI Show information',
});
const callout = page.locator('.cds--popover--open');
await expect(slug).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/react-is": "~18.3.0",
"accessibility-checker": "^3.1.48",
"accessibility-checker": "^3.1.78",
"all-contributors-cli": "^6.19.0",
"cross-env": "^7.0.0",
"cross-spawn": "^7.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7448,6 +7448,9 @@ Map {
},
"SliderSkeleton" => Object {
"propTypes": Object {
"ariaLabel": Object {
"type": "string",
},
"className": Object {
"type": "string",
},
Expand All @@ -7457,6 +7460,9 @@ Map {
"twoHandles": Object {
"type": "bool",
},
"unstable_ariaLabelHandleUpper": Object {
"type": "string",
},
},
},
"Stack" => Object {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/AILabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export const AILabel = React.forwardRef<HTMLDivElement, AILabelProps>(

const ariaLabelText =
!aiTextLabel && !textLabel
? `${aiText} - ${slugLabel || ariaLabel}`
: `${aiText} - ${aiTextLabel || textLabel}`;
? `${aiText} ${slugLabel || ariaLabel}`
: `${aiText} ${aiTextLabel || textLabel}`;

return (
<div className={aiLabelClasses} ref={ref} id={id}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ describe('ComposedModal', () => {
);

expect(
screen.getByRole('button', { name: 'AI - Show information' })
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
spy.mockRestore();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('NumberInput', () => {
);

expect(
screen.getByRole('button', { name: 'AI - Show information' })
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
});

Expand All @@ -84,7 +84,7 @@ describe('NumberInput', () => {
render(<NumberInput label="test-label" id="test" slug={<AILabel />} />);

expect(
screen.getByRole('button', { name: 'AI - Show information' })
screen.getByRole('button', { name: 'AI Show information' })
).toBeInTheDocument();
spy.mockRestore();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Popover/Popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const TabTip = () => {
<PopoverContent className="p-3">
<RadioButtonGroup
style={{ alignItems: 'flex-start', flexDirection: 'column' }}
legendText="Row height"
legendText="Row height 1"
name="radio-button-group"
defaultSelected="small">
<RadioButton labelText="Small" value="small" id="radio-small" />
Expand Down Expand Up @@ -146,7 +146,7 @@ export const TabTip = () => {
<PopoverContent className="p-3">
<RadioButtonGroup
style={{ alignItems: 'flex-start', flexDirection: 'column' }}
legendText="Row height"
legendText="Row height 2"
name="radio-button-group-2"
defaultSelected="small-2">
<RadioButton labelText="Small" value="small-2" id="radio-small-2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ describe('Select', () => {
it('should have no Accessibility Checker violations', async () => {
const { container } = render(
<main>
<Select id="select" labelText="Select">
<Select
id="select"
labelText="Select an option"
aria-label="Select an option">
<SelectItem value="option-1" text="Option 1" />
<SelectItem value="option-2" text="Option 2" />
</Select>
Expand Down
30 changes: 26 additions & 4 deletions packages/react/src/components/Slider/Slider.Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import classNames from 'classnames';
import { LowerHandle, UpperHandle } from './SliderHandles';

export interface SliderSkeletonProps extends HTMLAttributes<HTMLDivElement> {
/**
* The `ariaLabel` for the handle icon.
*/
ariaLabel?: string;

/**
* The `ariaLabel` for the upper bound slider handle when there are two handles.
*/
unstable_ariaLabelHandleUpper?: string;

/**
* Specify an optional className to add to the form item wrapper.
*/
Expand All @@ -31,6 +41,8 @@ export interface SliderSkeletonProps extends HTMLAttributes<HTMLDivElement> {
}

const SliderSkeleton = ({
ariaLabel = 'slider handle',
unstable_ariaLabelHandleUpper: ariaLabelHandleUpper = 'upper slider handle',
hideLabel,
className,
twoHandles,
Expand Down Expand Up @@ -82,19 +94,19 @@ const SliderSkeleton = ({
<div className={lowerThumbWrapperClasses}>
<div className={lowerThumbClasses}>
{twoHandles && !isRtl ? (
<LowerHandle />
<LowerHandle aria-label={ariaLabel} />
) : twoHandles && isRtl ? (
<UpperHandle />
<UpperHandle aria-label={ariaLabelHandleUpper} />
) : undefined}
</div>
</div>
{twoHandles ? (
<div className={upperThumbWrapperClasses}>
<div className={upperThumbClasses}>
{twoHandles && !isRtl ? (
<UpperHandle />
<UpperHandle aria-label={ariaLabelHandleUpper} />
) : twoHandles && isRtl ? (
<LowerHandle />
<LowerHandle aria-label={ariaLabel} />
) : undefined}
</div>
</div>
Expand All @@ -107,6 +119,16 @@ const SliderSkeleton = ({
};

SliderSkeleton.propTypes = {
/**
* The `ariaLabel` for the handle icon.
*/
ariaLabel: PropTypes.string,

/**
* The `ariaLabel` for the upper bound slider handle when there are two handles.
*/
unstable_ariaLabelHandleUpper: PropTypes.string,

/**
* Specify an optional className to add to the form item wrapper.
*/
Expand Down
18 changes: 10 additions & 8 deletions packages/react/src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1533,13 +1533,13 @@ class Slider extends PureComponent<SliderProps> {
}>
{twoHandles && !isRtl ? (
<>
<LowerHandle />
<LowerHandleFocus />
<LowerHandle aria-label={ariaLabelInput} />
<LowerHandleFocus aria-label={ariaLabelInput} />
</>
) : twoHandles && isRtl ? (
<>
<UpperHandle />
<UpperHandleFocus />
<UpperHandle aria-label={ariaLabelInputUpper} />
<UpperHandleFocus aria-label={ariaLabelInputUpper} />
</>
) : undefined}
</div>
Expand All @@ -1565,13 +1565,15 @@ class Slider extends PureComponent<SliderProps> {
}>
{twoHandles && !isRtl ? (
<>
<UpperHandle />
<UpperHandleFocus />
<UpperHandle aria-label={ariaLabelInputUpper} />
<UpperHandleFocus
aria-label={ariaLabelInputUpper}
/>
</>
) : twoHandles && isRtl ? (
<>
<LowerHandle />
<LowerHandleFocus />
<LowerHandle aria-label={ariaLabelInput} />
<LowerHandleFocus aria-label={ariaLabelInput} />
</>
) : undefined}
</div>
Expand Down
20 changes: 12 additions & 8 deletions packages/react/src/components/Slider/SliderHandles.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { PrefixContext } from '../../internal/usePrefix';
import React from 'react';

export const LowerHandle = () => (
export const LowerHandle = (props) => (
<PrefixContext.Consumer>
{(prefix) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 24"
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--lower`}>
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--lower`}
{...props}>
<path d="M15.08 6.46H16v11.08h-.92zM4.46 17.54c-.25 0-.46-.21-.46-.46V6.92a.465.465 0 0 1 .69-.4l8.77 5.08a.46.46 0 0 1 0 .8l-8.77 5.08c-.07.04-.15.06-.23.06Z" />
<path fill="none" d="M-4 0h24v24H-4z" />
</svg>
)}
</PrefixContext.Consumer>
);

export const LowerHandleFocus = () => (
export const LowerHandleFocus = (props) => (
<PrefixContext.Consumer>
{(prefix) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 24"
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--lower ${prefix}--slider__thumb-icon--focus`}>
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--lower ${prefix}--slider__thumb-icon--focus`}
{...props}>
<path d="M15.08 6.46H16v11.08h-.92zM4.46 17.54c-.25 0-.46-.21-.46-.46V6.92a.465.465 0 0 1 .69-.4l8.77 5.08a.46.46 0 0 1 0 .8l-8.77 5.08c-.07.04-.15.06-.23.06Z" />
<path fill="none" d="M-4 0h24v24H-4z" />
<path d="M15.08 0H16v6.46h-.92z" />
Expand All @@ -32,27 +34,29 @@ export const LowerHandleFocus = () => (
</PrefixContext.Consumer>
);

export const UpperHandle = () => (
export const UpperHandle = (props) => (
<PrefixContext.Consumer>
{(prefix) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 24"
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--upper`}>
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--upper`}
{...props}>
<path d="M0 6.46h.92v11.08H0zM11.54 6.46c.25 0 .46.21.46.46v10.15a.465.465 0 0 1-.69.4L2.54 12.4a.46.46 0 0 1 0-.8l8.77-5.08c.07-.04.15-.06.23-.06Z" />
<path fill="none" d="M-4 0h24v24H-4z" />
</svg>
)}
</PrefixContext.Consumer>
);

export const UpperHandleFocus = () => (
export const UpperHandleFocus = (props) => (
<PrefixContext.Consumer>
{(prefix) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 24"
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--upper ${prefix}--slider__thumb-icon--focus`}>
className={`${prefix}--slider__thumb-icon ${prefix}--slider__thumb-icon--upper ${prefix}--slider__thumb-icon--focus`}
{...props}>
<path d="M0 6.46h.92v11.08H0zM11.54 6.46c.25 0 .46.21.46.46v10.15a.465.465 0 0 1-.69.4L2.54 12.4a.46.46 0 0 1 0-.8l8.77-5.08c.07-.04.15-.06.23-.06Z" />
<path fill="none" d="M-4 0h24v24H-4z" />
<path d="M.92 24H0v-6.46h.92z" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import Slider from './Slider';
import Slider from '../Slider';
import userEvent from '@testing-library/user-event';
import { fireEvent, render, screen } from '@testing-library/react';

Expand Down Expand Up @@ -574,9 +574,9 @@ describe('Slider', () => {
it('should render children as expected', () => {
renderTwoHandleSlider();
const lowerElems = screen.getAllByLabelText(defaultAriaLabelInput);
expect(lowerElems).toHaveLength(2);
expect(lowerElems).toHaveLength(4);
const upperElems = screen.getAllByLabelText(defaultAriaLabelInputUpper);
expect(upperElems).toHaveLength(2);
expect(upperElems).toHaveLength(4);
});

it('should apply the expected classes', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import SliderSkeleton from '../Slider.Skeleton';

describe('SliderSkeleton', () => {
describe('behaves as expected - Component API', () => {
it('should apply the expected classes', () => {
const { container } = render(<SliderSkeleton />);
expect(container.firstChild.firstChild).toHaveClass(
'cds--label cds--skeleton'
);
});

it('should pass custom class via className', () => {
const customSliderClass = 'slider-custom-class';
const { container } = render(
<SliderSkeleton twoHandles={true} className={customSliderClass} />
);
expect(container.firstChild).toHaveClass(customSliderClass);
});

it('renders without label when hideLabel is true', () => {
const { container } = render(<SliderSkeleton hideLabel={true} />);
const label = container.querySelector('.cds--label.cds--skeleton');
expect(label).not.toBeInTheDocument();
});

describe('Accessibility labels', () => {
it('applies default aria labels', () => {
render(<SliderSkeleton twoHandles={true} />);
const lowerHandle = screen.getByLabelText('slider handle');
const upperHandle = screen.getByLabelText('upper slider handle');
expect(lowerHandle).toBeInTheDocument();
expect(upperHandle).toBeInTheDocument();
});

it('allows custom aria labels', () => {
render(
<SliderSkeleton
twoHandles={true}
ariaLabel="Custom Lower Handle"
unstable_ariaLabelHandleUpper="Custom Upper Handle"
/>
);
const lowerHandle = screen.getByLabelText('Custom Lower Handle');
const upperHandle = screen.getByLabelText('Custom Upper Handle');
expect(lowerHandle).toBeInTheDocument();
expect(upperHandle).toBeInTheDocument();
});
});
});
});
Loading

0 comments on commit 812d029

Please sign in to comment.