Svelte: A11y: <figcaption> must be an immediate child of <figure>

Created on 27 Apr 2019  路  2Comments  路  Source: sveltejs/svelte

<script>
    let caption = 'Lorem ipsum';
</script>

<figure>
    <img src="https://placekitten.com/200/300" alt="kitty" />
    {#if caption}
        <figcaption>{caption}</figcaption>
    {/if}
</figure>

This outputs the following warning: A11y: <figcaption> must be an immediate child of <figure>

REPL: https://svelte.dev/repl?version=3.1.0&gist=81856872f651e9f460d8f7497dedceb5

bug

Most helpful comment

I think we should probably just be looking for the nearest ancestor of the Element node type, and making sure that it's a <figure>.

All 2 comments

I wonder what blocks should be discarded when checking the figure/figcaption relationship.

Possibly {#if}, {:else if}, {:else}, and {#await}, {:then}, {:catch}?

<script>
  let caption = 'foo';
  let captionPromise = Promise.resolve('foo');
</script>

<figure>
  <img src="https://placekitten.com/200/300" alt="kitty" />
  {#if caption === 'foo'}
    <figcaption>{caption}</figcaption>
  {:else if caption === 'bar'}
    <figcaption>{caption}</figcaption>
  {:else}
    <figcaption>{caption}</figcaption>
  {/if}
</figure>

<figure>
  <img src="https://placekitten.com/200/300" alt="kitty" />
  {#await captionPromise}
    <figcaption>Loading</figcaption>
  {:then c}
    <figcaption>{c}</figcaption>
  {:catch e}
    <figcaption>{e}</figcaption>
  {/await}
</figure>

I think we should probably just be looking for the nearest ancestor of the Element node type, and making sure that it's a <figure>.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidcallanan picture davidcallanan  路  3Comments

robnagler picture robnagler  路  3Comments

lnryan picture lnryan  路  3Comments

thoughtspile picture thoughtspile  路  3Comments

plumpNation picture plumpNation  路  3Comments