diff --git a/docs/index.html b/docs/index.html
index 0a5d941..7b1e3de 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,9 +1,11 @@
-
-
-
{this.getIcon('checked')}
diff --git a/src/component/util.js b/src/component/util.js
index 44b2c19..0d0d270 100644
--- a/src/component/util.js
+++ b/src/component/util.js
@@ -18,3 +18,26 @@ export function pointerCoord (event) {
}
return { x: 0, y: 0 }
}
+
+export function checkForLabel (toggleContainer, input) {
+ return (hasParentLabel(toggleContainer, 'LABEL') || hasIdThatMatchesLabelFor(input) || hasAriaLabelOrAriaLabelledbyAttr(input)) ||
+ console.warn('There seems to not be any associated label for the react-toggle element. https://www.w3.org/standards/webdesign/accessibility')
+}
+
+export function hasParentLabel (element, tagName) {
+ return (element.parentNode && element.parentNode.nodeName === tagName)
+ ? true
+ : (!element.parentNode)
+ ? false
+ : hasParentLabel(element.parentNode, tagName)
+}
+
+export function hasIdThatMatchesLabelFor (element, document = window.document) {
+ return element.id
+ ? Array.from(document.querySelectorAll('label')).some(label => label.htmlFor === element.id)
+ : false
+}
+
+export function hasAriaLabelOrAriaLabelledbyAttr (element) {
+ return !!element.getAttribute('aria-label') || !!element.getAttribute('aria-labelledby')
+}