Skip to content

Commit 23b21a4

Browse files
authored
Merge pull request #22806 from Yoast/22756-ai-consent-popup-wrongly-appears-in-the-wordpress-profile-page
Enhance event handling for consent button in AI generator modal
2 parents 3953764 + 7acd3ba commit 23b21a4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/js/src/ai-consent/initialize.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ domReady( () => {
2929
const [ isModalOpen, , , openModal, closeModal ] = useToggleState( false );
3030
const focusElementRef = useRef( null );
3131
const handleClick = useCallback( e => {
32-
e.preventDefault();
32+
// Only react to trusted events.
33+
if ( ! e.isTrusted ) {
34+
return;
35+
}
36+
37+
// Only react when the button itself is the target/currentTarget.
38+
if ( e.currentTarget !== e.target ) {
39+
return false;
40+
}
3341
openModal();
3442
}, [ openModal ] );
3543

@@ -57,6 +65,7 @@ domReady( () => {
5765
<button
5866
className="button"
5967
id="ai-generator-consent-button"
68+
type="button"
6069
onClick={ handleClick }
6170
>
6271
{ hasConsent

0 commit comments

Comments
 (0)