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

Add generic forwarding of events and fix focus outlines #2

Closed
wants to merge 7 commits into from

Conversation

dslatkin
Copy link

@dslatkin dslatkin commented Mar 11, 2024

Closes #1

📑 Description

This PR adds general event delegation to the icons. Right now the library only forwards explicit events with on:click, on:keydown, etc. event forwarders.

svelte-preprocess-delegate-events supports the general forwarding of events with a new on:* directive. This PR adds that dependency according to its README instructions and converts the current forwarders to a generic forwarder that the proprocessor uses. Using this library also means Svelte won't set up inert event listeners by default, fixing the focus issue identified in #1.

Svelte 5 should fix this so this would only be a temporary solution until it's released.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

ℹ Additional Information

This all seems to work in my testing. I've npm run build && npm run preview and tried adding click, focus, and blur listeners to the icons using in the /icons route and they still work even after converting everything to use the preprocessor with the on:* directive.

There might be a better way to test installing the package as a dep. If you want I could do that and/or add some integration tests.

Also, here's the shell script I used to update the files:
#!/bin/bash

remove_lines=(
    on:click
    on:keydown
    on:keyup
    on:focus
    on:blur
    on:mouseenter
    on:mouseleave
    on:mouseover
    on:mouseout
)

for f in ./*.svelte;
do
    for line in "${remove_lines[@]}"; do
        sed -i "/$line/d" "$f"
    done
    sed -i '/  aria-label={ariaLabel}/a \  on:*' "$f"
done

Thank you!

Copy link

vercel bot commented Mar 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-radix ❌ Failed (Inspect) Mar 11, 2024 5:27am

@shinokada
Copy link
Owner

d1bab2f solved this problem.

@shinokada shinokada closed this Mar 11, 2024
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.

[BUG]: Forwarding on:focus and on:blur events on the icons causes unpredictable focus behavior
2 participants