From eddd52a862e68e655621deb84349edecf3b0f445 Mon Sep 17 00:00:00 2001 From: redallen Date: Tue, 9 Apr 2019 12:40:02 -0400 Subject: [PATCH 01/11] fix(aria): make aria-* props consistent --- .../src/components/AboutModal/AboutModal.js | 8 +- .../components/AboutModal/AboutModal.test.js | 6 +- .../AboutModal/AboutModalContainer.js | 14 +-- .../AboutModal/AboutModalContainer.test.js | 4 +- .../AboutModalContainer.test.js.snap | 8 +- .../react-core/src/components/Alert/Alert.js | 4 +- .../Alert/AlertActionCloseButton.js | 4 +- .../src/components/Alert/AlertActionLink.js | 2 +- .../src/components/Alert/AlertBody.js | 8 +- .../Alert/__snapshots__/Alert.test.js.snap | 24 ---- .../ApplicationLauncher.js | 10 +- ...Toggle.js => ApplicationLauncherToggle.js} | 0 .../src/components/ChipGroup/Chip.js | 54 +++++---- .../src/components/ChipGroup/ChipButton.js | 27 +++-- .../src/components/ChipGroup/ChipGroup.js | 47 ++++---- .../__snapshots__/ChipGroup.test.js.snap | 4 +- .../ContextSelector/ContextSelector.js | 16 +-- .../src/components/DataList/DataListAction.js | 67 +++++----- .../components/DataList/DataListContent.js | 31 ++--- .../src/components/DataList/DataListItem.js | 35 +++--- .../src/components/Dropdown/Dropdown.js | 2 +- .../src/components/Dropdown/Dropdown.test.js | 1 - .../src/components/Dropdown/KebabToggle.js | 24 ++-- .../src/components/Dropdown/Toggle.js | 6 +- .../__snapshots__/Dropdown.test.js.snap | 78 ++++++------ .../src/components/LoginPage/LoginForm.js | 13 +- .../components/LoginPage/LoginForm.test.js | 18 +-- .../__snapshots__/LoginForm.test.js.snap | 8 +- .../react-core/src/components/Modal/Modal.js | 8 +- .../src/components/Modal/ModalBox.test.js | 6 +- .../src/components/Modal/ModalContent.js | 8 +- .../Modal/__snapshots__/ModalBox.test.js.snap | 3 - .../src/components/Pagination/OptionsMenu.js | 1 + .../__snapshots__/Pagination.test.js.snap | 30 ++--- .../src/components/Select/CheckboxSelect.js | 4 + .../components/Select/CheckboxSelectInput.js | 2 +- .../Select/GroupedCheckboxSelectInput.js | 2 +- .../src/components/Select/Select.js | 6 +- .../Select/__snapshots__/Select.test.js.snap | 10 +- .../react-core/src/components/Tabs/Tabs.js | 55 ++++++--- .../Tabs/__snapshots__/Tabs.test.js.snap | 65 +++++----- .../Table/__snapshots__/Table.test.js.snap | 114 +++++++++--------- 42 files changed, 415 insertions(+), 422 deletions(-) rename packages/patternfly-4/react-core/src/components/ApplicationLauncher/{Toggle.js => ApplicationLauncherToggle.js} (100%) diff --git a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.js b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.js index 5d96033afc7..cb61dcad9f6 100644 --- a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.js +++ b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.js @@ -52,8 +52,8 @@ class AboutModal extends React.Component { static propTypes = propTypes; static defaultProps = defaultProps; - ariaLabelledbyId = `pf-about-modal-title-${currentId++}`; - ariaDescribedById = `pf-about-modal-content-${currentId++}`; + ariaLabelledBy = `pf-about-modal-title-${currentId++}`; + ariaDescribedBy = `pf-about-modal-content-${currentId++}`; handleEscKeyClick = event => { if (event.keyCode === KEY_CODES.ESCAPE_KEY && this.props.isOpen) { @@ -96,8 +96,8 @@ class AboutModal extends React.Component { return ReactDOM.createPortal( , this.container ); diff --git a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.test.js b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.test.js index d98f61c08d0..aecd8d2b852 100644 --- a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.test.js +++ b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModal.test.js @@ -48,11 +48,11 @@ test('modal does not call onClose for esc key if it is not open', () => { expect(props.onClose).not.toBeCalled(); }); -test('Each modal is given new ariaDescribedById and ariaLablledbyId', () => { +test('Each modal is given new aria-describedby and aria-lablledby', () => { const first = shallow( Test About Modal ); const second = shallow( Test About Modal ); - expect(first.props().ariaLabelledbyId).not.toBe(second.props().ariaLabelledbyId); - expect(first.props().ariaDescribedById).not.toBe(second.props().ariaDescribedById); + expect(first.props()['aria-labelledby']).not.toBe(second.props()['aria-labelledby']); + expect(first.props()['aria-describedby']).not.toBe(second.props()['aria-describedby']); }); test('Console error is generated when the logoImageSrc is provided without logoImageAlt', () => { diff --git a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.js b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.js index 6763067c314..40f988413ee 100644 --- a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.js +++ b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.js @@ -31,9 +31,9 @@ const propTypes = { /** the alternate text of the Logo image. */ logoImageAlt: PropTypes.string.isRequired, /** id to use for About Modal Box aria labeled by */ - ariaLabelledbyId: PropTypes.string.isRequired, + 'aria-labelledby': PropTypes.string.isRequired, /** id to use for About Modal Box aria described by */ - ariaDescribedById: PropTypes.string.isRequired, + 'aria-describedby': PropTypes.string.isRequired, /** Additional props are spread to the AboutModalBoxContent component */ '': PropTypes.any }; @@ -55,8 +55,8 @@ const ModalContent = ({ brandImageAlt, logoImageSrc, logoImageAlt, - ariaLabelledbyId, - ariaDescribedById, + 'aria-labelledby': ariaLabelledBy, + 'aria-describedby': ariaDescribedBy, ...props }) => { if (!isOpen) { @@ -65,11 +65,11 @@ const ModalContent = ({ return ( - + - - + + {children} diff --git a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.test.js b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.test.js index 2c396770fcf..620fedbea60 100644 --- a/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.test.js +++ b/packages/patternfly-4/react-core/src/components/AboutModal/AboutModalContainer.test.js @@ -10,8 +10,8 @@ const props = { brandImageAlt: 'Brand Image', logoImageSrc: 'logoImg...', logoImageAlt: 'AboutModal Logo', - ariaLabelledbyId: 'ariaLablledbyId', - ariaDescribedById: 'ariaDescribedById' + 'aria-labelledby': 'ariaLabelledBy', + 'aria-describedby': 'ariaDescribedBy' }; test('About Modal Container Test simple', () => { const view = shallow(This is ModalBox content); diff --git a/packages/patternfly-4/react-core/src/components/AboutModal/__snapshots__/AboutModalContainer.test.js.snap b/packages/patternfly-4/react-core/src/components/AboutModal/__snapshots__/AboutModalContainer.test.js.snap index 666d84a0590..358c4a98930 100644 --- a/packages/patternfly-4/react-core/src/components/AboutModal/__snapshots__/AboutModalContainer.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/AboutModal/__snapshots__/AboutModalContainer.test.js.snap @@ -9,8 +9,8 @@ exports[`About Modal Container Test isOpen 1`] = ` component="div" > diff --git a/packages/patternfly-4/react-core/src/components/Alert/Alert.js b/packages/patternfly-4/react-core/src/components/Alert/Alert.js index c63389e714c..96fb1ab25d7 100644 --- a/packages/patternfly-4/react-core/src/components/Alert/Alert.js +++ b/packages/patternfly-4/react-core/src/components/Alert/Alert.js @@ -72,7 +72,9 @@ const Alert = ({ )} {action && ( -
{React.cloneElement(action, { title, variantLabel })}
+
+ {React.cloneElement(action, { title, variantLabel })} +
)} ); diff --git a/packages/patternfly-4/react-core/src/components/Alert/AlertActionCloseButton.js b/packages/patternfly-4/react-core/src/components/Alert/AlertActionCloseButton.js index 7ff94816628..84ff0128f0f 100644 --- a/packages/patternfly-4/react-core/src/components/Alert/AlertActionCloseButton.js +++ b/packages/patternfly-4/react-core/src/components/Alert/AlertActionCloseButton.js @@ -20,11 +20,11 @@ const defaultProps = { onClose: () => undefined }; -const AlertActionCloseButton = ({ className, onClose, 'aria-label': ariaLabel, title, variantLabel, ...props }) => ( +const AlertActionCloseButton = ({ className, onClose, variantLabel, 'aria-label': ariaLabel, title, variant, ...props }) => ( diff --git a/packages/patternfly-4/react-core/src/components/Alert/AlertBody.js b/packages/patternfly-4/react-core/src/components/Alert/AlertBody.js index d32690603de..445b517c04a 100644 --- a/packages/patternfly-4/react-core/src/components/Alert/AlertBody.js +++ b/packages/patternfly-4/react-core/src/components/Alert/AlertBody.js @@ -10,7 +10,7 @@ const propTypes = { children: PropTypes.node, className: PropTypes.string, onClose: PropTypes.func, - closeButtonAriaLabel: PropTypes.string + 'aria-label': PropTypes.string }; const defaultProps = { @@ -18,13 +18,13 @@ const defaultProps = { children: '', className: '', onClose: undefined, - closeButtonAriaLabel: 'Close' + 'aria-label': 'Close' }; -const AlertBody = ({ title, className, children, onClose, closeButtonAriaLabel, ...props }) => ( +const AlertBody = ({ title, className, children, onClose, 'aria-label': ariaLabel, ...props }) => (
{onClose && ( - )} diff --git a/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.js.snap b/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.js.snap index 2e252bce718..0bc222bc6c6 100644 --- a/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/Alert/__snapshots__/Alert.test.js.snap @@ -221,7 +221,6 @@ exports[`Alert - danger Action Link 1`] = ` title="" type="button" variant="link" - variantLabel="Danger" > @@ -331,7 +329,6 @@ exports[`Alert - danger Action and Title 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Danger" > @@ -442,7 +438,6 @@ exports[`Alert - danger Custom aria label 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Danger" > @@ -817,7 +811,6 @@ exports[`Alert - info Action Link 1`] = ` title="" type="button" variant="link" - variantLabel="Info" > @@ -927,7 +919,6 @@ exports[`Alert - info Action and Title 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Info" > @@ -1038,7 +1028,6 @@ exports[`Alert - info Custom aria label 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Info" > @@ -1413,7 +1401,6 @@ exports[`Alert - success Action Link 1`] = ` title="" type="button" variant="link" - variantLabel="Success" > @@ -1523,7 +1509,6 @@ exports[`Alert - success Action and Title 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Success" > @@ -1634,7 +1618,6 @@ exports[`Alert - success Custom aria label 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Success" > @@ -2009,7 +1991,6 @@ exports[`Alert - warning Action Link 1`] = ` title="" type="button" variant="link" - variantLabel="Warning" > @@ -2119,7 +2099,6 @@ exports[`Alert - warning Action and Title 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Warning" > @@ -2230,7 +2208,6 @@ exports[`Alert - warning Custom aria label 1`] = ` title="Some title" type="button" variant="link" - variantLabel="Warning" > diff --git a/packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncher.js b/packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncher.js index 62c5ce78523..17601d1ea93 100644 --- a/packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncher.js +++ b/packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncher.js @@ -3,7 +3,7 @@ import styles from '@patternfly/patternfly/components/AppLauncher/app-launcher.c import { css } from '@patternfly/react-styles'; import PropTypes from 'prop-types'; import ApplicationLauncherMenu from './ApplicationLauncherMenu'; -import Toggle from './Toggle'; +import ApplicationLauncherToggle from './ApplicationLauncherToggle'; import { ThIcon } from '@patternfly/react-icons'; import { ApplicationLauncherDirection, ApplicationLauncherPosition } from './applicationLauncherConstants'; import { DropdownContext } from '../Dropdown/dropdownConstants'; @@ -51,13 +51,11 @@ class ApplicationLauncher extends React.Component { render() { const { 'aria-label': ariaLabel, - children, dropdownItems, className, isOpen, onSelect, onToggle, - ...props } = this.props; return ( @@ -69,16 +67,16 @@ class ApplicationLauncher extends React.Component { }} > {Children.map( - + - , + , oneToggle => cloneElement(oneToggle, { parentRef: this.parentRef, id: randomId, isOpen, isPlain: true, - ariaHasPopup: true, + 'aria-haspopup': 'true', onEnter: this.onEnter }) )} diff --git a/packages/patternfly-4/react-core/src/components/ApplicationLauncher/Toggle.js b/packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncherToggle.js similarity index 100% rename from packages/patternfly-4/react-core/src/components/ApplicationLauncher/Toggle.js rename to packages/patternfly-4/react-core/src/components/ApplicationLauncher/ApplicationLauncherToggle.js diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/Chip.js b/packages/patternfly-4/react-core/src/components/ChipGroup/Chip.js index ba3f056bdd0..8f107c9612f 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/Chip.js +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/Chip.js @@ -7,6 +7,30 @@ import { TimesCircleIcon } from '@patternfly/react-icons'; import styles from '@patternfly/patternfly/components/Chip/chip.css'; import GenerateId from '../../helpers/GenerateId/GenerateId'; +const propTypes = { + /** Content rendered inside the chip text */ + children: PropTypes.node, + /** Aria Label for close button */ + 'aria-label': PropTypes.string, + /** Additional classes added to the chip item */ + className: PropTypes.string, + /** Flag indicating if the chip has overflow */ + isOverflowChip: PropTypes.bool, + /** Function that is called when clicking on the chip button */ + onClick: PropTypes.func, + /** Position of the tooltip which is displayed if text is longer */ + tooltipPosition: PropTypes.oneOf(Object.values(TooltipPosition)) +}; + +const defaultProps = { + children: null, + 'aria-label': 'close', + className: '', + isOverflowChip: false, + tooltipPosition: 'top', + onClick: () => { } +}; + class Chip extends React.Component { span = React.createRef(); state = { isTooltipVisible: false }; @@ -29,7 +53,7 @@ class Chip extends React.Component { }; renderChip = randomId => { - const { children, closeBtnAriaLabel, tooltipPosition, className, onClick } = this.props; + const { children, 'aria-label': ariaLabel, tooltipPosition, className, onClick } = this.props; if (this.state.isTooltipVisible) { return ( @@ -39,7 +63,7 @@ class Chip extends React.Component { @@ -56,7 +80,7 @@ class Chip extends React.Component { @@ -73,28 +97,8 @@ class Chip extends React.Component { ); } } -Chip.propTypes = { - /** Content rendered inside the chip text */ - children: PropTypes.node, - /** Aria Label for close button */ - closeBtnAriaLabel: PropTypes.string, - /** Additional classes added to the chip item */ - className: PropTypes.string, - /** Flag indicating if the chip has overflow */ - isOverflowChip: PropTypes.bool, - /** Function that is called when clicking on the chip button */ - onClick: PropTypes.func, - /** Position of the tooltip which is displayed if text is longer */ - tooltipPosition: PropTypes.oneOf(Object.values(TooltipPosition)) -}; -Chip.defaultProps = { - children: null, - closeBtnAriaLabel: 'close', - className: '', - isOverflowChip: false, - tooltipPosition: 'top', - onClick: () => {} -}; +Chip.propTypes = propTypes; +Chip.defaultProps = defaultProps; export default Chip; diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipButton.js b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipButton.js index 73a3a37e1d9..443c9e51f25 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipButton.js +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipButton.js @@ -1,18 +1,10 @@ import React from 'react'; -import { css } from '@patternfly/react-styles'; import PropTypes from 'prop-types'; -import styles from '@patternfly/patternfly/components/Chip/chip.css'; import { Button } from '../Button'; -const ChipButton = ({ ariaLabel, children, className, onClick, ...props }) => ( - -); - -ChipButton.propTypes = { +const propTypes = { /** Aria label for chip button */ - ariaLabel: PropTypes.string, + 'aria-label': PropTypes.string, /** Content rendered inside the chip item */ children: PropTypes.node, /** Additional classes added to the chip item */ @@ -21,11 +13,20 @@ ChipButton.propTypes = { onClick: PropTypes.func }; -ChipButton.defaultProps = { - ariaLabel: 'close', +const defaultProps = { + 'aria-label': 'close', children: null, className: '', - onClick: () => {} + onClick: () => { } }; +const ChipButton = ({ children, ...props }) => ( + +); + +ChipButton.propTypes = propTypes; +ChipButton.defaultProps = defaultProps; + export default ChipButton; diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.js b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.js index 7a613a52485..3af35536e33 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.js +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.js @@ -5,6 +5,29 @@ import styles from '@patternfly/patternfly/components/ChipGroup/chip-group.css'; import { Chip } from '@patternfly/react-core'; import { fillTemplate } from '../../helpers'; +const propTypes = { + /** Content rendered inside the chip text */ + children: PropTypes.node, + /** Additional classes added to the chip item */ + className: PropTypes.string, + /** Customizable "Show Less" text string */ + expandedText: PropTypes.string, + /** + * Customizeable template string. Use variable "${remaining}" for the overflow chip count. + */ + collapsedText: PropTypes.string, + /** Flag for grouping with a toolbar & category name */ + withToolbar: PropTypes.bool +}; + +const defaultProps = { + children: null, + className: '', + expandedText: 'Show Less', + collapsedText: '${remaining} more', + withToolbar: false +}; + class ChipGroup extends React.Component { state = { isOpen: false @@ -64,27 +87,7 @@ const InnerChipGroup = props => { ); }; -ChipGroup.propTypes = { - /** Content rendered inside the chip text */ - children: PropTypes.node, - /** Additional classes added to the chip item */ - className: PropTypes.string, - /** Customizable "Show Less" text string */ - expandedText: PropTypes.string, - /** - * Customizeable template string. Use variable "${remaining}" for the overflow chip count. - */ - collapsedText: PropTypes.string, - /** Flag for grouping with a toolbar & category name */ - withToolbar: PropTypes.bool -}; - -ChipGroup.defaultProps = { - children: null, - className: '', - expandedText: 'Show Less', - collapsedText: '${remaining} more', - withToolbar: false -}; +ChipGroup.propTypes = propTypes; +ChipGroup.defaultProps = defaultProps; export default ChipGroup; diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.js.snap b/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.js.snap index 461b12432b1..bf222b0c0f8 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.js.snap @@ -13,8 +13,8 @@ exports[`ChipGroup chip group default 1`] = ` withToolbar={false} > {}, - onSelect: () => {}, + onToggle: () => { }, + onSelect: () => { }, screenReaderLabel: '', toggleText: '', - searchButtonAriaLabel: 'Search menu items', + 'aria-label': 'Search menu items', searchInputValue: '', - onSearchInputChange: () => {}, + onSearchInputChange: () => { }, searchInputPlaceholder: 'Search', - onSearchButtonClick: () => {} + onSearchButtonClick: () => { } }; class ContextSelector extends React.Component { @@ -79,7 +79,7 @@ class ContextSelector extends React.Component { onSelect, screenReaderLabel, toggleText, - searchButtonAriaLabel, + 'aria-label': ariaLabel, searchInputValue, onSearchInputChange, searchInputPlaceholder, @@ -121,7 +121,7 @@ class ContextSelector extends React.Component { /> ); diff --git a/packages/patternfly-4/react-core/src/components/DataList/__snapshots__/DataList.test.js.snap b/packages/patternfly-4/react-core/src/components/DataList/__snapshots__/DataList.test.js.snap index c5fbc4809b0..19b7893f05a 100644 --- a/packages/patternfly-4/react-core/src/components/DataList/__snapshots__/DataList.test.js.snap +++ b/packages/patternfly-4/react-core/src/components/DataList/__snapshots__/DataList.test.js.snap @@ -37,6 +37,8 @@ exports[`DataList DataListAction button 1`] = ` exports[`DataList DataListAction dropdown 1`] = `
Date: Tue, 9 Apr 2019 18:39:56 -0400 Subject: [PATCH 11/11] fix tabs passing aria-label to ); @@ -109,7 +114,12 @@ const TabsWithDiv = ({ highlightRightScrollButton && styles.modifiers.endCurrent, className)} > - +
);