Skip to content

Instantly share code, notes, and snippets.

@MustSeeMelons
Created December 22, 2020 15:04
Show Gist options
  • Save MustSeeMelons/7a94f4b756d1ee56d648e1fc0aeba073 to your computer and use it in GitHub Desktop.
Save MustSeeMelons/7a94f4b756d1ee56d648e1fc0aeba073 to your computer and use it in GitHub Desktop.
Show The Logs Harold - Element content search
useEffect(() => {
const children = jsonRef.current.getElementsByTagName("*");
const childArray = [].slice.call(children) as HTMLElement[];
const filterElements: HTMLElement[] = [];
childArray.forEach((el) => {
if (
el.textContent &&
el.textContent.includes(props.filterValue) &&
el.children.length === 0 &&
props.currentFilteredJson
) {
filterElements.push(el);
el.style.backgroundColor = props.theme.colors.primary.accentText;
el.style.color = props.theme.colors.primary.lightText;
} else {
el.style.backgroundColor = "inherit";
el.style.color = "inherit";
}
});
props.setFilterElements(filterElements);
}, [props.currentFilteredJson, jsonRef, props.isUiLocked]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment