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

Having trouble implementing this. #325

Open
fallenturtle opened this issue Jul 11, 2024 · 9 comments
Open

Having trouble implementing this. #325

fallenturtle opened this issue Jul 11, 2024 · 9 comments
Labels
documentation Improvements or additions to documentation

Comments

@fallenturtle
Copy link

fallenturtle commented Jul 11, 2024

I'm having some sort of syntax issue I think getting this off the ground. I've added:
import { DisclosureMenu } from "https://esm.sh/[email protected]";
to my js file, but the console gives a syntax error:
mainnav.js?v=9.5.9:1 Uncaught SyntaxError: The requested module 'https://esm.sh/[email protected]' does not provide an export named 'DisclosureMenu'

I also tried pointing the import statement at the location of the file in my project, but that gives me the same error:
import { DisclosureMenu } from "/libraries/accessible-menu/dist/disclosure-menu.iife.js";

I tried removing the {} from around DisclosureMenu but then it says its not a constructor.
Any idea what I'm doing wrong? Thanks!

Here's a codepen of the issues I'm running into https://codepen.io/fallenturtle/pen/vYqOOXw

@fallenturtle fallenturtle added the documentation Improvements or additions to documentation label Jul 11, 2024
@NickDJM
Copy link
Owner

NickDJM commented Jul 12, 2024

esm.sh looks like it does something weird with the exports. Looks like you'd have to do:

import AccessibleMenu from "https://esm.sh/[email protected]";

const menu = new AccessibleMenu.DisclosureMenu({...});

That's not super ideal, but it'll work. I'll see if I can change that somewhere in the project. Maybe there's something I can define for esm.sh.

Your local example doesn't work because the iife formatted files just declare the menu globally. If you want to use imports, you can do:

import DisclosureMenu from "libraries/accessible-menu/dist/disclosure-menu.es.js";

const menu - new DisclosureMenu({...});

If you want to use the iife file, then you can just add it as a script above your own in your html:

<script src="/libraries/accessible-menu/dist/disclosure-menu.iife.js"></script>
<script>
  // You can use DisclosureMenu globally anywhere under here.

  const menu - new DisclosureMenu({...});
</script>

@fallenturtle
Copy link
Author

Thank you, I was able to get it working.

@NickDJM NickDJM closed this as completed Jul 16, 2024
@stierpm
Copy link

stierpm commented Jul 22, 2024

I'm sorry, but I am also unable to get this implemented and am running into similar errors using the recommended approach in the docs.
Screenshot 2024-07-22 at 11 18 56
Screenshot 2024-07-22 at 11 19 08
Screenshot 2024-07-22 at 11 19 48

@NickDJM NickDJM reopened this Jul 22, 2024
@NickDJM
Copy link
Owner

NickDJM commented Jul 22, 2024

@stierpm How are you including the library? NPM, jsdelivr, esm.sh, etc.?

@stierpm
Copy link

stierpm commented Jul 22, 2024

@NickDJM - jsdelivr
Screenshot 2024-07-22 at 12 43 27

@NickDJM
Copy link
Owner

NickDJM commented Jul 22, 2024

@stierpm Ah ok, the iife just exposes a global class for you so theoretically you can just remove your import line and move on.

Once you do that, you're currently importing the entire library so you'll need to use new AccessibleMenu.DisclosureMenu({ ... }) instead of new DisclosureMenu({ ... }).

If you are only planning on using the DisclosureMenu class, then I would recommend importing https://cdn.jsdelivr.net/npm/accessible-menu/dist/disclosure-menu.iife.js instead of the entire library; It's a lot smaller.

Also, if you would like to use imports then use the .es.js files instead of the .iife.js ones. They're set up to be used as modules.

@NickDJM
Copy link
Owner

NickDJM commented Jul 31, 2024

@stierpm Following up on this. Did it work following the advice above? If so, I'll close this.

@stierpm
Copy link

stierpm commented Jul 31, 2024

@NickDJM - This did work, but overall, did not end up working for my particular situation. I found a different solution though that does work. Thank you for following up and sorry for the delayed response.

I would consider updating the documentation page accordingly, however.

@NickDJM
Copy link
Owner

NickDJM commented Sep 3, 2024

@stierpm Are you able to post your solution? That way I can look into incorporating a few different examples into the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants