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

Expose 'name' attribute for MenuItem #4168

Open
reecebenson opened this issue Mar 12, 2021 · 3 comments
Open

Expose 'name' attribute for MenuItem #4168

reecebenson opened this issue Mar 12, 2021 · 3 comments

Comments

@reecebenson
Copy link

reecebenson commented Mar 12, 2021

Feature Request

Problem description

When using Semantic UI React with Elastic APM (for real user monitoring), we get unhelpful log messages such as "Click - div" or "Click - a", as the monitoring library relies on the name attribute to give it a concise definition. As an example, I want to have Click - a["authorTab"] logged when clicking on a Tab's MenuItem so Elastic RUM can provide network activity (API requests) when changing tabs, etc.

Tab:

Tab Code Example

Menu:

Menu Code Example

Proposed solution

The solution here is to expose the name attribute for the MenuItem component which will reflect for both Tab MenuItems and regular navigation MenuItem's too. Code examples can be found in the MVP below.

MVP

https://codesandbox.io/s/semantic-ui-react-forked-gnxi3

@welcome
Copy link

welcome bot commented Mar 12, 2021

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@reecebenson
Copy link
Author

@layershifter Any thoughts as to when this could get triaged? :-)

@layershifter
Copy link
Member

@reecebenson it took me some time to get there, sorry about that. Honestly, it's our bad design decision that we used name as it collides with HTML attributes.

image

According to MDN (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes) name cannot be combined with divs or as that MenuItem renders. So I am not sure that it's the best idea to implement it as proposed in #4169.

I went through elastic/apm-agent-rum-js#969, but not sure that I understood the problem. In the worst case you can apply patch on your side with patch-package.

Another workaround is apply it manually to DOM:

function CustomMenuItem(props) {
  const ref = React.useRef();

  React.useLayoutEffect(() => {
    ref.current.setAttribute("name", props.name);
  }, [props.name]);

  return (
    <Ref innerRef={ref}>
      <Menu.Item {...props} />
    </Ref>
  );
}

https://codesandbox.io/s/semantic-ui-react-forked-v0heo?file=/index.js:136-387

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 a pull request may close this issue.

2 participants