Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add data-nuxt-img and data-nuxt-pic attrs #747

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/runtime/components/nuxt-img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineComponent({
type AttrsT = typeof _base.attrs.value & {
sizes?: string
srcset?: string
'data-nuxt-img'?: string
}

const sizes = computed(() => $img.getSizes(props.src, {
Expand All @@ -36,7 +37,7 @@ export default defineComponent({
}))

const attrs = computed(() => {
const attrs: AttrsT = _base.attrs.value
const attrs: AttrsT = { ..._base.attrs.value, 'data-nuxt-img': '' }
if (props.sizes) {
attrs.sizes = sizes.value.sizes
attrs.srcset = sizes.value.srcset
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/nuxt-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default defineComponent({
}

// Only passdown supported <image> attributes
const imgAttrs = { ...props.imgAttrs }
const imgAttrs: Record<string, string | unknown> = { ...props.imgAttrs, 'data-nuxt-pic': '' }
for (const key in ctx.attrs) {
if (key in baseImageProps && !(key in imgAttrs)) {
imgAttrs[key] = ctx.attrs[key]
Expand Down