Skip to content

Commit 03222c2

Browse files
samuelreichertgjulivan
authored andcommitted
feat(combobox-web): add custom hook to check for associated label in inputs
1 parent 7b9cf71 commit 03222c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useEffect, useState } from "react";
2+
3+
export function useHasLabel(inputId: string): boolean {
4+
const [hasLabel, setHasLabel] = useState(false);
5+
6+
useEffect(() => {
7+
const label = document.querySelector(`label[for="${inputId}"]`);
8+
9+
setHasLabel(!!label);
10+
}, [inputId]);
11+
12+
return hasLabel;
13+
}

0 commit comments

Comments
 (0)