From eb070d4a1d1184365dfbe38c6ccddc18ffeab311 Mon Sep 17 00:00:00 2001 From: devartes Date: Fri, 10 Feb 2023 18:53:47 -0300 Subject: [PATCH] =?UTF-8?q?refactor(Placeholder.tsx):=20corrigindo=20l?= =?UTF-8?q?=C3=B3gica=20do=20componente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react/components/Placeholder/Placeholder.tsx | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/react/components/Placeholder/Placeholder.tsx b/react/components/Placeholder/Placeholder.tsx index 7840422..f242ac3 100644 --- a/react/components/Placeholder/Placeholder.tsx +++ b/react/components/Placeholder/Placeholder.tsx @@ -1,16 +1,29 @@ const Placeholder = () => { if (typeof document !== "undefined") { - const postalCodeInput = document.querySelector( - ".vtex-address-form-4-x-input" - ); - const postalCodeValue = document.querySelector(".postalCode"); - if (postalCodeInput) { - postalCodeInput.classList.add("postalCode"); - } - if (postalCodeValue) { - postalCodeValue.setAttribute("placeholder", "Digite seu CEP"); - } + const observer = new MutationObserver(mutations => { + mutations.forEach(_mutation => { + const postalCodeInput = document.querySelector( + ".vtex-address-form-4-x-input" + ); + const postalCodeValue = document.querySelector(".postalCode"); + + if (postalCodeInput) { + postalCodeInput.classList.add("postalCode"); + observer.disconnect(); + } + + if (postalCodeValue) { + postalCodeValue.setAttribute("placeholder", "Digite seu CEP"); + } + }); + }); + + observer.observe(document, { + childList: true, + subtree: true + }); } + return null; };