Skip to content

Commit

Permalink
feat(VIcon): Add 'tag' prop to VIcon that sets a custom tag to be used
Browse files Browse the repository at this point in the history
Add a new optional prop to VIcon, the 'tag' prop, that specifies a custom tag to use in the
component, similar to the tag prop from VContainer. If none is provided, the component will fallback
to use <i> as the tag, for the benefit of backwards compatibility.
  • Loading branch information
FRFlor committed Apr 2, 2019
1 parent 59bdbec commit 558777e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/vuetify/src/components/VIcon/VIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ const VIcon = mixins(
props: {
disabled: Boolean,
left: Boolean,
right: Boolean
right: Boolean,
tag: {
type: String,
required: false,
default: 'i'
}
},

methods: {
Expand Down Expand Up @@ -104,7 +109,7 @@ const VIcon = mixins(

this.applyColors(data)

return h('i', data, newChildren)
return h(this.tag, data, newChildren)
},
renderSvgIcon (icon: VuetifyIconComponent, h: CreateElement): VNode {
const data = this.getDefaultData()
Expand Down
16 changes: 15 additions & 1 deletion packages/vuetify/test/unit/components/VIcon/VIcon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ test('VIcon.js', ({ mount, compileToFunctions }) => {
expect(clickHandler).toBeCalled()
})

it('should use an <i> tag if none provided', () => {
const context = functionalContext({}, 'add')
const wrapper = mount(VIcon, context)

expect(wrapper.element.localName).toBe('i')
});

it('sets tag from from prop if provided', () => {
const context = functionalContext({ props: { tag: 'span' } }, 'add')
const wrapper = mount(VIcon, context)

expect(wrapper.element.localName).toBe('span')
});

describe('for component icon', () => {
const getTestComponent = () => ({
props: ['name'],
Expand Down Expand Up @@ -253,7 +267,7 @@ test('VIcon.js', ({ mount, compileToFunctions }) => {
const context = functionalContext({ on: { click: clickHandler } }, '$vuetify.icons.testIcon')
const wrapper = mount(VIcon, context)
wrapper.trigger('click')

expect(wrapper.element.classList).toContain('v-icon--link')
expect(clickHandler).toBeCalled()
})
Expand Down

0 comments on commit 558777e

Please sign in to comment.