-
Notifications
You must be signed in to change notification settings - Fork 135
useSref: "target="_blank" ignored when link contains child elements #1224
Copy link
Copy link
Open
Description
mishra-ankit-learn
opened on Mar 20, 2024
Issue body actions
- Issue Example:
- https://codesandbox.io/p/sandbox/uirouter-react-ussref-blank-target-not-working-with-div-inside-a-992y2s
- Issue:
- useSref handles click when anchor element contains a child element. This is an issue when the user wants the browser to handle the onClick event, by providing a target attribute.
- Use Case:
- The user wants the link to open in a new tab
- Cause:
- In Fix fix(sref): do not handle clicks if the dom element has a 'target' attribute Also do not handle clicks if shift or alt is being held down. #799 the targetAttr (line#87) is captured from e.target assuming that the mouse event got triggered from the anchor. But when there is a child element present inside the anchor element, the mouse event triggers the child element. The child element does not have a target attribute, which makes useSref handle the onClick.
- Fix:
- Although the target attribute is not present in e.target, it is in e.currentTarget. So we should check for e.currentTarget when getting targetAttr
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels