Skip to content

Commit

Permalink
fix(nuxt-picture): render svgs with src not srcset
Browse files Browse the repository at this point in the history
danielroe committed May 29, 2023
1 parent b3a9089 commit 46939f1
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/components/nuxt-picture.ts
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ export default defineComponent({
type Source = { srcset: string, src?: string, type?: string, sizes?: string }
const sources = computed<Source[]>(() => {
if (format.value === 'svg') {
return [<Source>{ srcset: props.src }]
return [<Source>{ src: props.src }]
}

const formats = legacyFormat.value !== format.value
9 changes: 9 additions & 0 deletions test/unit/picture.test.ts
Original file line number Diff line number Diff line change
@@ -80,4 +80,13 @@ describe('Renders simple image', () => {
const sizes = wrapper.find('source').element.getAttribute('sizes')
expect(sizes).toBe('(max-width: 500px) 500px, 900px')
})

it('renders src when svg is passed', () => {
const wrapper = mount(NuxtPicture, {
propsData: {
src: '/image.svg'
}
})
expect(wrapper.html()).toMatchInlineSnapshot('"<picture><img data-nuxt-pic=\\"\\" src=\\"/image.svg\\"></picture>"')
})
})

0 comments on commit 46939f1

Please sign in to comment.