Skip to content

Commit

Permalink
chore: move setAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Jul 11, 2024
1 parent 07f9e6e commit cdaa5d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from "react"
const useIsWalletConnectModalActive = () => {
const [isWalletConnectModalActive, setIsWalletConnectModalActive] = useState(false)

const w3mModalRef = useRef(null)
const w3mModalRef = useRef<Element | null>(null)
useEffect(() => {
if (typeof window === "undefined" || w3mModalRef.current) return
w3mModalRef.current = document.querySelector("wcm-modal")
Expand All @@ -17,6 +17,8 @@ const useIsWalletConnectModalActive = () => {

if (!observerTarget) return

observerTarget.setAttribute("aria-label", "Web3ConnectionManager")

const mutationCallback: MutationCallback = (mutations, _) => {
const classNameChange = mutations.find(
(mutation) => mutation.attributeName === "class"
Expand Down
28 changes: 0 additions & 28 deletions src/v2/components/Web3ConnectionManager/Web3ConnectionManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,5 @@ export function Web3ConnectionManagerBase() {
export function Web3ConnectionManager() {
useTriggerWalletSelectorModal()

// a11y: WCM misses label from their modal
useEffect(() => {
function waitQuerySelector(selector: string): Promise<Element> {
return new Promise((resolve) => {
const elem = document.querySelector(selector)
if (elem) {
return resolve(elem)
}
const observer = new MutationObserver(() => {
const elem = document.querySelector(selector)
if (elem) {
observer.disconnect()
resolve(elem)
}
})
observer.observe(document.body, {
childList: true,
subtree: true,
})
})
}
waitQuerySelector("wcm-modal").then((element) => {
element?.shadowRoot
?.getElementById("wcm-modal")
?.setAttribute("aria-label", "Web3ConnectionManager")
})
}, [])

return <Web3ConnectionManagerBase />
}

0 comments on commit cdaa5d2

Please sign in to comment.