Check if a figcaption's first element ancestor is a figure

pull/2607/head
Emil Tholin 5 years ago
parent 93f7ecca1d
commit 6ebd72fc22

@ -224,7 +224,21 @@ export default class Element extends Node {
}
if (this.name === 'figcaption') {
if (this.parent.name !== 'figure') {
let { parent } = this;
let is_figure_parent = false;
while (parent) {
if (parent.name === 'figure') {
is_figure_parent = true;
break;
}
if (parent.type === 'Element') {
break;
}
parent = parent.parent;
}
if (!is_figure_parent) {
this.component.warn(this, {
code: `a11y-structure`,
message: `A11y: <figcaption> must be an immediate child of <figure>`

@ -0,0 +1,10 @@
<script>
let caption = 'a foo in its natural habitat';
</script>
<figure>
<img src='foo.jpg' alt='a picture of a foo'>
{#if caption}
<figcaption>{caption}</figcaption>
{/if}
</figure>
Loading…
Cancel
Save