File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
packages/compass-components/src/components/actions Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -48,15 +48,19 @@ export function DropdownMenuButton<Action extends string>({
4848 const menuTriggerRef = useRef < HTMLButtonElement | null > ( null ) ;
4949 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
5050
51- const onClick = useCallback (
51+ const onClick : React . MouseEventHandler < HTMLElement > = useCallback (
5252 ( evt ) => {
5353 evt . stopPropagation ( ) ;
5454 if ( evt . currentTarget . dataset . menuitem ) {
5555 setIsMenuOpen ( false ) ;
5656 // Workaround for https://jira.mongodb.org/browse/PD-1674
5757 menuTriggerRef . current ?. focus ( ) ;
5858 }
59- onAction ( evt . currentTarget . dataset . action ) ;
59+ const actionName = evt . currentTarget . dataset . action ;
60+ if ( typeof actionName !== 'string' ) {
61+ throw new Error ( 'Expected element to have a "data-action" attribute' ) ;
62+ }
63+ onAction ( actionName as Action ) ;
6064 } ,
6165 [ onAction ]
6266 ) ;
Original file line number Diff line number Diff line change @@ -43,10 +43,14 @@ export function ItemActionGroup<Action extends string>({
4343 isVisible = true ,
4444 'data-testid' : dataTestId ,
4545} : ItemActionGroupProps < Action > ) {
46- const onClick = useCallback (
46+ const onClick : React . MouseEventHandler < HTMLElement > = useCallback (
4747 ( evt ) => {
4848 evt . stopPropagation ( ) ;
49- onAction ( evt . currentTarget . dataset . action ) ;
49+ const actionName = evt . currentTarget . dataset . action ;
50+ if ( typeof actionName !== 'string' ) {
51+ throw new Error ( 'Expected element to have a "data-action" attribute' ) ;
52+ }
53+ onAction ( actionName as Action ) ;
5054 } ,
5155 [ onAction ]
5256 ) ;
Original file line number Diff line number Diff line change @@ -61,15 +61,19 @@ export function ItemActionMenu<Action extends string>({
6161 const menuTriggerRef = useRef < HTMLButtonElement | null > ( null ) ;
6262 const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
6363
64- const onClick = useCallback (
64+ const onClick : React . MouseEventHandler < HTMLElement > = useCallback (
6565 ( evt ) => {
6666 evt . stopPropagation ( ) ;
6767 if ( evt . currentTarget . dataset . menuitem ) {
6868 setIsMenuOpen ( false ) ;
6969 // Workaround for https://jira.mongodb.org/browse/PD-1674
7070 menuTriggerRef . current ?. focus ( ) ;
7171 }
72- onAction ( evt . currentTarget . dataset . action ) ;
72+ const actionName = evt . currentTarget . dataset . action ;
73+ if ( typeof actionName !== 'string' ) {
74+ throw new Error ( 'Expected element to have a "data-action" attribute' ) ;
75+ }
76+ onAction ( actionName as Action ) ;
7377 } ,
7478 [ onAction ]
7579 ) ;
You can’t perform that action at this time.
0 commit comments