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 SVG support? #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add SVG support? #232

wants to merge 1 commit into from

Conversation

srushe
Copy link

@srushe srushe commented Mar 21, 2023

Hello. I've made a small-ish update to add support for using an inline SVG as a customToggle. This fixes a javascript error I've encountered when I tried this for a site I'm working on. I'm putting this PR up in case it might be worth applying, but obviously feel free to ignore it if it doesn't fit.

The error I encountered is...

Uncaught TypeError: el.className.indexOf is not a function
    addClass http://localhost:1313/j/responsive-nav.js:152
    open http://localhost:1313/j/responsive-nav.js:301
    toggle http://localhost:1313/j/responsive-nav.js:286
    _onTouchEnd http://localhost:1313/j/responsive-nav.js:584
    handleEvent http://localhost:1313/j/responsive-nav.js:386
    addEvent http://localhost:1313/j/responsive-nav.js:56
    _init http://localhost:1313/j/responsive-nav.js:432
    ResponsiveNav http://localhost:1313/j/responsive-nav.js:246
    responsiveNav http://localhost:1313/j/responsive-nav.js:653
    <anonymous> http://localhost:1313/:1381

The documentation on MDN regarding className mentions that if the element is an SVG then className returns an instance of SVGAnimatedString, rather than a string, which causes the error.

I've updated responsive-nav.js to use getAttribute to determine the class name, as well as using setAttribute to set the new class name, as recommended on MDN.

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.

1 participant