Skip to content

fix: warnings in examples page #8836

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

Merged
merged 3 commits into from
Jun 26, 2023

Conversation

AlimurtuzaCodes
Copy link
Contributor

What does this PR do

Fixes all warnings in examples page.

@AlimurtuzaCodes
Copy link
Contributor Author

@dummdidumm @PuruVJ .

Copy link
Member

@geoffrich geoffrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! There's a few issues I see:

  • some of the places where you added role='button' would be better to use an actual <button> element. This is because we use role=button, we also have to listen for key events and handle Space and Enter appropriately. It's simpler to just use the native button
  • some of the examples heavily rely on mouse movement so can't really be made accessible by adding buttons. We may want to rethink these examples in the future to not be so mouse-reliant but for now should ignore the warnings instead of adding roles that don't actually make the example more accessible.
  • some of the warnings you resolved were false positives and should be rightfully ignored.

I think this PR shows that our current a11y warnings could definitely be improved to be more helpful and/or actionable (and avoid warnings that are false positives). They're pretty ARIA-heavy right now, and in most cases the solution is to use native HTML elements instead of ARIA. But that's something to be tackled separately from this PR.

@@ -7,7 +7,7 @@
}
</script>

<div on:mousemove={handleMousemove}>
<div on:mousemove={handleMousemove} role='button' tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay as is - the tutorial is showing reacting to mouse movements. Adding role="button" tabindex="0" doesn't help here. It would be better to ignore the warning instead, at least for now.

@@ -28,6 +28,7 @@
{:else}
<ul>
{#each [...eases] as [name]}
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of ignoring the warnings here, nest a button inside the <li> instead and apply the click handler there. e.g.

<li><button on:click={() => (current_ease = name)}>{name}</button></li>

(note: this may require adjusting some styles)

@@ -46,6 +47,7 @@
{:else}
<ul>
{#each types as [name, type]}
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above - create a button inside the <li> instead of ignoring the warnings

<dialog
bind:this={dialog}
on:close={() => (showModal = false)}
on:click|self={() => dialog.close()}
>
<div on:click|stopPropagation>
<div on:click|stopPropagation role='button' tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be made a button - the click handler is just listening to all child events. In this case it's okay to ignore the warning since screen reader users have other ways to close a native dialog and don't need to use this click handler.

@@ -11,7 +11,8 @@
}
</script>

<span class:expanded on:click={toggle}>{name}</span>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span class:expanded on:click={toggle} role='button' tabindex='0'>{name}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it would be better to make this a native <button> element instead of applying role + tabindex. This is because we use role=button, we also have to listen for key events and handle Space and Enter appropriately. It's simpler to just use the native button

@@ -15,7 +15,8 @@

<!-- the text will flash red whenever
the `todo` object changes -->
<div bind:this={div} on:click>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div bind:this={div} on:click role="button" tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ignoring this warning, we should add a button instead that will complete the todo and attach the click handler to that

@@ -2,7 +2,7 @@
let m = { x: 0, y: 0 };
</script>

<div on:mousemove={(e) => (m = { x: e.clientX, y: e.clientY })}>
<div on:mousemove={(e) => (m = { x: e.clientX, y: e.clientY })} role='button' tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment - we should ignore this warning instead of adding role="button" (which won't help in this case)

@@ -28,6 +28,7 @@
on:mousemove={(e) => coords.set({ x: e.clientX, y: e.clientY })}
on:mousedown={() => size.set(30)}
on:mouseup={() => size.set(10)}
role='button' tabindex='0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ignore this warning for now - this tutorial is very reliant on mouse interactions, adding role="button" won't address the root issue

@@ -10,6 +10,6 @@
}
</script>

<div on:mouseenter={enter} on:mouseleave={leave}>
<div on:mouseenter={enter} on:mouseleave={leave} role="button" tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ignore this warning for now, since this example relies on hovering and can't be made keyboard accessible

Comment on lines 16 to 17
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div bind:this={div} on:click role="button" tabindex='0'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, we should add a button to complete todos instead of ignoring the warning

@AlimurtuzaCodes
Copy link
Contributor Author

Thanks for the PR! There's a few issues I see:

  • some of the places where you added role='button' would be better to use an actual <button> element. This is because we use role=button, we also have to listen for key events and handle Space and Enter appropriately. It's simpler to just use the native button
  • some of the examples heavily rely on mouse movement so can't really be made accessible by adding buttons. We may want to rethink these examples in the future to not be so mouse-reliant but for now should ignore the warnings instead of adding roles that don't actually make the example more accessible.
  • some of the warnings you resolved were false positives and should be rightfully ignored.

I think this PR shows that our current a11y warnings could definitely be improved to be more helpful and/or actionable (and avoid warnings that are false positives). They're pretty ARIA-heavy right now, and in most cases the solution is to use native HTML elements instead of ARIA. But that's something to be tackled separately from this PR.

I will fix the issues.

@AlimurtuzaCodes
Copy link
Contributor Author

@geoffrich Made the changes as per your request. Review it.

@dummdidumm
Copy link
Member

Thanks for updating these! I think what Geoff meant with "ignore this warning" was to add a <!-- svelte-ignore [warning code] --> for each a11y warning that still appears.

@AlimurtuzaCodes
Copy link
Contributor Author

AlimurtuzaCodes commented Jun 26, 2023

Thanks for updating these! I think what Geoff meant with "ignore this warning" was to add a <!-- svelte-ignore [warning code] --> for each a11y warning that still appears.

I have tried all the warning codes as per docs, but none of the warnings worked.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that it didn't work for you - I add the ignore tags which seems to silence them for me.

I think we're good to go now - thank you!

@dummdidumm dummdidumm merged commit bbcb5f5 into sveltejs:master Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants