Skip to content

Commit

Permalink
STCOM-1165: Format aria attributes in <Icon> (#2210)
Browse files Browse the repository at this point in the history
* STCOM-1165: Format aria attributes in `<Icon>`

* STCOM-1165: fix test for icon
  • Loading branch information
UladzislauKutarkin authored Jan 17, 2024
1 parent 6ea7862 commit fbfd705
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* TextLink - underline showing up on nested spans with 'display: inline-flex'. Refs STCOM-1226.
* Use the default search option instead of an unsupported one in Advanced search. Refs STCOM-1242.
* Added support for clear icon in `<TextArea>`. Refs STCOM-1240.
* Format aria attributes in `<Icon>`. Refs STCOM-1165.

## [12.0.0](https://github.com/folio-org/stripes-components/tree/v12.0.0) (2023-10-11)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v11.0.0...v12.0.0)
Expand Down
15 changes: 13 additions & 2 deletions lib/Icon/Icon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { pickBy, get } from 'lodash';
import {
pickBy,
get,
mapKeys
} from 'lodash';
import css from './Icon.css';
import icons from './icons';

Expand Down Expand Up @@ -87,14 +91,21 @@ const Icon = React.forwardRef(({

const ariaAttributes = pickBy(rest, (_, key) => key.startsWith('aria'));

const formattedAriaAttributes = mapKeys(ariaAttributes, (_, key) => {
if (key.startsWith('aria')) {
return key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
return key;
});

return (
<span
className={getRootClass}
id={id}
ref={ref}
role="presentation"
tabIndex={tabIndex}
{...ariaAttributes}
{...formattedAriaAttributes}
>
<IconElement
data-test-icon-element
Expand Down
1 change: 0 additions & 1 deletion lib/Icon/tests/Icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('Icon', () => {
await mount(
<Icon
id="icon-id"
ariaLabel="icon-title"
tabIndex="0"
icon="bookmark"
iconClassName={iconClassName}
Expand Down

0 comments on commit fbfd705

Please sign in to comment.