import React from 'react' ; import { ApplicationStart } from 'src/core/public' ; import { getClosestLink , hasActiveModifierKey } from './utils' ; interface CreateCrossAppClickHandlerOptions { container : HTMLElement ; navigateToUrl : ApplicationStart [ 'navigateToUrl' ] ; } export const createNavigateToUrlClickHandler = ( { container , navigateToUrl , } ) : React . MouseEventHandler < HTMLElement > => { return ( e ) => { if ( container == null ) { return ; } const target = e . target as HTMLElement ; const link = getClosestLink ( target , container ) ; if ( ! link ) { return ; } if ( link . href && ( link . target === '' || link . target === '_self' ) && e . button === 0 && ! e . defaultPrevented && ! hasActiveModifierKey ( e ) ) { e . preventDefault ( ) ; navigateToUrl ( link . href ) ; } } ; } ;