Skip to content

Commit

Permalink
fix: don't rely on global sr-only classname to hide the icons from th…
Browse files Browse the repository at this point in the history
…e IconsProvider (#5051)
  • Loading branch information
romainseb authored Dec 11, 2023
1 parent 1bc49cd commit 266df87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-flies-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/design-system': patch
---

fix: don't rely on global sr-only classname to hide the icons from the IconsProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.hidden {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
white-space: nowrap;
width: 1px;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { VisuallyHidden } from '../VisuallyHidden';
import { ReactElement, RefObject, useEffect, useRef, useState } from 'react';

import classNames from 'classnames';

import assetsAPI from '@talend/assets-api';
import { ReactElement, RefObject, useState, useEffect, useRef } from 'react';

import style from './IconsProvider.module.scss';

const DEFAULT_BUNDLES = [
assetsAPI.getURL('/dist/svg-bundle/all.svg', '@talend/icons'),
Expand Down Expand Up @@ -85,7 +89,7 @@ function addBundle(response: Response, url: string) {
return response.text().then(content => {
if (content.startsWith('<svg')) {
const container = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
container.setAttribute('class', 'tc-iconsprovider sr-only');
container.setAttribute('class', classNames('tc-iconsprovider', style.hidden));
container.setAttribute('aria-hidden', 'true');
container.setAttribute('focusable', 'false');
container.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
Expand Down Expand Up @@ -159,20 +163,18 @@ export function IconsProvider({

return (
(shouldRender && (
<VisuallyHidden>
<svg
xmlns="http://www.w3.org/2000/svg"
focusable="false"
className="tc-iconsprovider"
ref={ref}
>
{Object.keys(iconset).map((id, index) => (
<symbol key={index} id={id}>
{iconset[id]}
</symbol>
))}
</svg>
</VisuallyHidden>
<svg
xmlns="http://www.w3.org/2000/svg"
focusable="false"
className={classNames('tc-iconsprovider', style.hidden)}
ref={ref}
>
{Object.keys(iconset).map((id, index) => (
<symbol key={index} id={id}>
{iconset[id]}
</symbol>
))}
</svg>
)) ||
null
);
Expand Down

0 comments on commit 266df87

Please sign in to comment.