Skip to content

Commit

Permalink
fix(b-icon): use aria-label attribute instead of alt (bootstrap-v…
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmllr95 authored Jul 16, 2020
1 parent 1964363 commit 72a1363
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/icons/helpers/icon-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const baseAttrs = {
height: '1em',
focusable: 'false',
role: 'img',
alt: 'icon'
'aria-label': 'icon'
}

// Attributes that are nulled out when stacked
Expand All @@ -61,7 +61,7 @@ const stackedAttrs = {
height: null,
focusable: null,
role: null,
alt: null
'aria-label': null
}

// Shared private base component to reduce bundle/runtime size
Expand Down
9 changes: 7 additions & 2 deletions src/icons/helpers/make-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { commonIconProps, BVIconBase } from './icon-base'
export const makeIcon = (name, content) => {
// For performance reason we pre-compute some values, so that
// they are not computed on each render of the icon component
const kebabName = kebabCase(name)
const iconName = `BIcon${pascalCase(name)}`
const iconNameClass = `bi-${kebabCase(name)}`
const iconNameClass = `bi-${kebabName}`
const svgContent = trim(content || '')
// Return the icon component definition
return /*#__PURE__*/ Vue.extend({
Expand All @@ -30,7 +31,11 @@ export const makeIcon = (name, content) => {
render(h, { data, props }) {
return h(
BVIconBase,
mergeData(data, { staticClass: iconNameClass, props: { ...props, content: svgContent } })
mergeData(data, {
staticClass: iconNameClass,
props: { ...props, content: svgContent },
attrs: { 'aria-label': kebabName.replace(/-/g, ' ') }
})
)
}
})
Expand Down
8 changes: 4 additions & 4 deletions src/icons/icons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('icons', () => {
expect(wrapper.classes()).toContain('bi-alarm-fill')
expect(wrapper.classes().length).toBe(3)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('alarm fill')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.attributes('xmlns')).toBe('http://www.w3.org/2000/svg')
expect(wrapper.attributes('width')).toBe('1em')
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('icons', () => {
expect(wrapper.classes()).toContain('bi-alarm-fill')
expect(wrapper.classes().length).toBe(3)
expect(wrapper.attributes('role')).not.toBe('img')
expect(wrapper.attributes('alt')).not.toBe('icon')
expect(wrapper.attributes('aria-label')).not.toBe('icon')
expect(wrapper.attributes('focusable')).not.toBe('false')
expect(wrapper.attributes('focusable')).not.toBe('true')
expect(wrapper.attributes('xmlns')).not.toBe('http://www.w3.org/2000/svg')
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('icons', () => {
expect(wrapper.classes()).toContain('text-danger')
expect(wrapper.classes().length).toBe(4)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('alarm fill')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.find('svg > g').exists()).toBe(true)
expect(wrapper.find('svg > g').attributes('transform')).not.toBeDefined()
Expand All @@ -178,7 +178,7 @@ describe('icons', () => {
expect(wrapper.classes()).toContain('bi-alarm-fill')
expect(wrapper.classes().length).toBe(3)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('alarm fill')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.attributes('style')).toBeDefined()
expect(wrapper.element.style.fontSize).toEqual('125%')
Expand Down
6 changes: 3 additions & 3 deletions src/icons/iconstack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('icons > b-iconstack', () => {
expect(wrapper.classes()).toContain('bi')
expect(wrapper.classes().length).toBe(3)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('icon')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.attributes('xmlns')).toBe('http://www.w3.org/2000/svg')
expect(wrapper.attributes('width')).toBe('1em')
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('icons > b-iconstack', () => {
expect(wrapper.classes()).toContain('text-danger')
expect(wrapper.classes().length).toBe(4)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('icon')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.find('svg > g').exists()).toBe(true)
expect(wrapper.find('svg > g').attributes('transform')).not.toBeDefined()
Expand All @@ -65,7 +65,7 @@ describe('icons > b-iconstack', () => {
expect(wrapper.classes()).toContain('bi')
expect(wrapper.classes().length).toBe(3)
expect(wrapper.attributes('role')).toBe('img')
expect(wrapper.attributes('alt')).toBe('icon')
expect(wrapper.attributes('aria-label')).toBe('icon')
expect(wrapper.attributes('focusable')).toBe('false')
expect(wrapper.attributes('style')).toBeDefined()
expect(wrapper.element.style.fontSize).toEqual('125%')
Expand Down

0 comments on commit 72a1363

Please sign in to comment.