File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/** State management singleton for internal use. This should not be used directly in applications. */
22
33import { UCUICMPEvent , UCUICMPEventType } from '../types.js'
4- import { hasUserInteracted , IS_BROWSER } from '../utils.js'
4+ import { hasUserInteracted , IS_BROWSER , isOpen } from '../utils.js'
55
66export type ServiceState = {
77 hasInteracted : boolean
@@ -56,7 +56,7 @@ const initializeState = () => {
5656
5757 if ( ! state . isInitialized && IS_BROWSER && 'UC_UI' in window ) {
5858 shouldUpdate = true
59- state = { ...state , isInitialized : true }
59+ state = { ...state , isInitialized : true , isOpen : isOpen ( ) }
6060 }
6161
6262 const hasInteracted = hasUserInteracted ( )
Original file line number Diff line number Diff line change @@ -152,3 +152,16 @@ export const updateLanguage = (countryCode: string) => {
152152 ; ( window as UCWindow ) . UC_UI ?. updateLanguage ?.( countryCode )
153153 }
154154}
155+
156+ /**
157+ * Returns true if the Usercentrics dialog is currently open.
158+ */
159+ export const isOpen = ( ) : boolean => {
160+ if ( IS_BROWSER ) {
161+ const usercentricsRoot = document . getElementById ( 'usercentrics-root' )
162+ const dialog = usercentricsRoot ?. shadowRoot ?. querySelector ( '[role="dialog"]' )
163+ return ! ! dialog
164+ }
165+
166+ return false
167+ }
You can’t perform that action at this time.
0 commit comments