accessible-menu icon indicating copy to clipboard operation
accessible-menu copied to clipboard

Having trouble implementing this.

Open fallenturtle opened this issue 1 year ago • 9 comments

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 avatar Jul 11 '24 23:07 fallenturtle

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>

NickDJM avatar Jul 12 '24 14:07 NickDJM

Thank you, I was able to get it working.

fallenturtle avatar Jul 13 '24 00:07 fallenturtle

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

stierpm avatar Jul 22 '24 17:07 stierpm

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

NickDJM avatar Jul 22 '24 18:07 NickDJM

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

stierpm avatar Jul 22 '24 18:07 stierpm

@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 avatar Jul 22 '24 19:07 NickDJM

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

NickDJM avatar Jul 31 '24 15:07 NickDJM

@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.

stierpm avatar Jul 31 '24 15:07 stierpm

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

NickDJM avatar Sep 03 '24 17:09 NickDJM

Closing as inactive.

NickDJM avatar Feb 04 '25 12:02 NickDJM