From cbf2a7d744a080a643f8af5447a501ddd0d0be61 Mon Sep 17 00:00:00 2001 From: Adilson Fernando Date: Sat, 28 Jan 2023 17:03:56 -0300 Subject: [PATCH] feat: placeholder do cep pronto e funcionando --- .../PlaceholderCep/PlaceholderCep.tsx | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/react/components/PlaceholderCep/PlaceholderCep.tsx b/react/components/PlaceholderCep/PlaceholderCep.tsx index ec52714..7ab5a58 100644 --- a/react/components/PlaceholderCep/PlaceholderCep.tsx +++ b/react/components/PlaceholderCep/PlaceholderCep.tsx @@ -1,15 +1,27 @@ +import React from "react"; const PlaceholderCep = () => { - - if (typeof document !== "undefined") { + new Promise(resolve => { + if (document.querySelectorAll(".vtex-address-form-4-x-input").length > 0) { + return resolve(Array.from(document.querySelectorAll(".vtex-address-form-4-x-input"))); + } - // document.getElementsByClassName("vtex-address-form-4-x-hideDecorators")[0].setAttribute("placeholder", "Digite seu CEP"); + const observer = new MutationObserver(() => { + if (document.querySelectorAll(".vtex-address-form-4-x-input").length > 0) { + resolve(document.querySelectorAll(".vtex-address-form-4-x-input")); + observer.disconnect(); + } + }); - // .placeholder = "Digite seu CEP" - - }; + observer.observe(document.body, { + childList: true, + subtree: true, + }); + }).then((els: any) => { + els[0].placeholder = "Digite seu CEP"; + }); - return "" ; -}; + return <>; +}; -export default PlaceholderCep; +export default PlaceholderCep; \ No newline at end of file