carbon icon indicating copy to clipboard operation
carbon copied to clipboard

[Question]: HeaderMenu component shortens url to `#`, is this a known Carbon bug?

Open angella-qian opened this issue 3 years ago • 3 comments

Question for Carbon

I've tried posting in our #carbon-react channel but haven't received any responses there so wanted to post and see if I could get any help with this here.

Wondering if someone has come across this or if this is a known Carbon bug. We’re seeing that anytime you click our HeaderMenu component, the url shortens to #. We're using the HeaderMenu here to allow users to create a new assistant or switch between existing assistants. I see on the implicit <a> tag there’s an href set to # so I’m thinking that’s what’s causing it. I’m unable to set a event.preventDefault() or event.stopPropagation() on this <a> tag though - I’ve tried adding it to the onClick handler of HeaderMenuItem and more.

URL

Related code:

  const openCreateModal = useCallback(() => {
    setIsCreateModalOpen(true);
  }, []);

  const handleSwitchAssistant = useCallback(
    id => {
      history.push(
        urlJoin(encodeURIComponent(instance), 'assistants', id, 'home')
      );
    },
    [history, instance]
  );

 <HeaderNavigation>
       <HeaderMenu
            menuLinkName={menuName}>
            <HeaderMenuItem onClick={openCreateModal}>
                <div>
                   Create New
                   <Add24 />
                 </div>
            </HeaderMenuItem>
            {assistants
              .filter(a => a.assistant_id !== assistant?.assistant_id) // Ignore the selected assistant
              .map(a => (
                  <HeaderMenuItem
                     onClick={() => handleSwitchAssistant(a.assistant_id)}
                     key={a.assistant_id}>
                        {a.name ?? 'Unnamed'}
                   </HeaderMenuItem>
              ))}
       </HeaderMenu>
</HeaderNavigation>

Code of Conduct

angella-qian avatar Mar 09 '22 18:03 angella-qian

Hi there, @angella-qian! 👋 Thanks for taking the time to put this issue together 🙏

I went ahead and opened up #10967 to remove the href="#" that is being set with HeaderMenu. For next steps, I'm going to double check with the team that this makes sense from an accessibility perspective. If it all checks out, we can merge it in.

Hope this makes sense! Let me know if you have any questions.

joshblack avatar Mar 11 '22 18:03 joshblack

@joshblack Hey, yep! And thanks for the quick response – just wondering if you have an eta of when this fix will go out?

angella-qian avatar Apr 06 '22 21:04 angella-qian

@joshblack Hey, I notice that the fix was closed without merging. Are we still going to have another fix to resolve the problem?

miniwangdali avatar Jul 29 '22 13:07 miniwangdali

Hi @angella-qian @miniwangdali there were some a11y concerns with the PR implementation that was opened for this issue. Unfortunately @joshblack has actually moved on to a new team 😢 At the moment, we don't have any further explorations planned, but we would welcome a PR to fix this 🙏🏽

jnm2377 avatar Aug 25 '22 05:08 jnm2377

Hey @angella-qian I was checking this issue and looks like have been fixed. I couldn't reproduce in the storybook. The "#" is not being placed in the URL.

If the error persists, could you reproduce it on Stackblitz, please?

guidari avatar Jan 03 '24 19:01 guidari

We will close this issue, but if you find this issue is not actually resolved, please open a new issue and include a link back to this issue.

guidari avatar Jan 10 '24 18:01 guidari