Skip to content

Commit

Permalink
ui-router#1224 - updated the comment to be more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
mishra-ankit-learn committed Mar 22, 2024
1 parent e05d973 commit dceb158
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/hooks/useSref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ export function useSref(stateName: string, params: object = {}, options: Transit

const onClick = useCallback(
(e: React.MouseEvent) => {
/* For scenario where we specify target="_blank" on a link that has a div as a child, to use browser's default onClick behavior,
the onClick event gets triggered on the div rather than the anchor tag.
The actual target is present inside the currentTarget property instead. So, targetAttr should be assigned from currentTarget,
so that router's go method does not get called and browser's default onClick behavior is triggered
currentTarget will always be set irrespective of anchor contains a child or not*/
/* We want to check attributes on the element that the click handler is on and not on whichever other element was clicked*/

const targetAttr = (e.currentTarget as any)?.attributes?.target;
const modifierKey = e.button >= 1 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey;
Expand Down

0 comments on commit dceb158

Please sign in to comment.