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

Cannot access "altText" inside images #243

Open
ttavni opened this issue Nov 19, 2023 · 2 comments
Open

Cannot access "altText" inside images #243

ttavni opened this issue Nov 19, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@ttavni
Copy link

ttavni commented Nov 19, 2023

I am using the sanityImage utility method and cannot access the altText which is an additional field. I'm not sure if there's be a change with sanity since the implementation but for example:

      image: sanityImage('image', {
        withAsset: ['base', 'lqip', 'dimensions'],
        additionalFields: {
          altText: q.string().nullable(),
        },
      })

It always returns null for the altText because the altText is inside asset. The only way I've got around this is

      image: sanityImage('image', {
        additionalFields: {
          asset: q('asset').deref(),
        },
        withAsset: ['base', 'lqip', 'dimensions'],
      }),

Which sort of defeats the point and ruins the types

@carbonrobot carbonrobot added the enhancement New feature or request label Nov 20, 2023
@carbonrobot
Copy link
Contributor

@ttavni Is your altText directly on the asset type and not as an extension of the image type or part of the asset metadata field?

Is it possible to post the schema of your image type?

@ttavni
Copy link
Author

ttavni commented Nov 20, 2023

@carbonrobot yes that's correctly. I am using the Sanity Media plugin (https://github.com/sanity-io/sanity-plugin-media) so it is automatically adding those fields and it's directly on the asset type - nothing extra in my schema.

I didn't realise about adding custom fields on images, that makes the additionalFields make more sense now 😅 but it is nice to store the alt text for images globally instead of individually through the media plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants