diff --git a/CHANGELOG.md b/CHANGELOG.md index fafc44d507f..8a16af93b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - Added `disabled` prop to the `EuiCheckboxGroup` definition ([#2545](https://github.com/elastic/eui/pull/2545)) - Added `disabled` option to the `option` attribute of the `options` object that is passed to the `EuiCheckboxGroup` so that checkboxes in a group can be individually disabled ([#2548](https://github.com/elastic/eui/pull/2548)) - Added `EuiAspectRatio` component that allows for responsively resizing embeds ([#2535](https://github.com/elastic/eui/pull/2535)) +- Fixed `EuiIcon` accessibility by adding a `title` prop and a default `aria-label` ([#2554](https://github.com/elastic/eui/pull/2554)) - Added `display` and `titleSize` props to `EuiCard` ([#2566](https://github.com/elastic/eui/pull/2566)) - Added `accessibility` glyph to `EuiIcon` ([#2566](https://github.com/elastic/eui/pull/2566)) diff --git a/scripts/compile-icons.js b/scripts/compile-icons.js index e4f1cd04555..98516bbd745 100644 --- a/scripts/compile-icons.js +++ b/scripts/compile-icons.js @@ -8,28 +8,12 @@ const srcDir = path.resolve(rootDir, 'src'); const iconsDir = path.resolve(srcDir, 'components', 'icon', 'assets'); function pascalCase(x) { - return x.replace(/^(.)|[^a-zA-Z]([a-zA-Z])/g, (match, char1, char2) => (char1 || char2).toUpperCase()); + return x.replace(/^(.)|[^a-zA-Z]([a-zA-Z])/g, (match, char1, char2) => + (char1 || char2).toUpperCase() + ); } -const iconFiles = glob.sync( - '**/*.svg', - { cwd: iconsDir, realpath: true } -); - -function defaultTemplate({ - template - }, opts, { - imports, - componentName, - props, - jsx, - exports - }) { - return template.ast`${imports} -const ${componentName} = (${props}) => ${jsx} -${exports} -`; -} +const iconFiles = glob.sync('**/*.svg', { cwd: iconsDir, realpath: true }); iconFiles.forEach(async filePath => { const svgSource = fs.readFileSync(filePath); @@ -40,7 +24,7 @@ iconFiles.forEach(async filePath => { throw new Error(`${filePath} is missing a 'viewBox' attribute`); } - const jsxSource = (await svgr( + const jsxSource = await svgr( svgSource, { plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'], @@ -52,18 +36,23 @@ iconFiles.forEach(async filePath => { ], }, svgProps: { - xmlns: 'http://www.w3.org/2000/svg' + xmlns: 'http://www.w3.org/2000/svg', }, - template: ({ template }, opts, { imports, componentName, props, jsx }) => template.ast` + titleProp: true, + template: ( + { template }, + opts, + { imports, componentName, props, jsx } + ) => template.ast` ${imports} const ${componentName} = (${props}) => ${jsx} export const icon = ${componentName}; - ` + `, }, { - componentName: `EuiIcon${pascalCase(path.basename(filePath, '.svg'))}` + componentName: `EuiIcon${pascalCase(path.basename(filePath, '.svg'))}`, } - )); + ); const outputFilePath = filePath.replace(/\.svg$/, '.js'); fs.writeFileSync(outputFilePath, jsxSource); diff --git a/src-docs/src/views/icon/accessibility.js b/src-docs/src/views/icon/accessibility.js index 8b5cadf5999..2152cd19d90 100644 --- a/src-docs/src/views/icon/accessibility.js +++ b/src-docs/src/views/icon/accessibility.js @@ -4,6 +4,6 @@ import { EuiIcon } from '../../../../src/components'; export default () => (
+ If the icon is purely decorative, pass{' '}
+
- Editor icons relate to the visual styling of elements and are
- commonly used within
- You can title the SVG by passing the
http://some.svg
@@ -59,7 +60,9 @@ export default () => (