(element: HTMLElement | null | undefined, key: string)
| 114 | } |
| 115 | |
| 116 | export function getElementDataset(element: HTMLElement | null | undefined, key: string) { |
| 117 | if (!element) { |
| 118 | return null; |
| 119 | } |
| 120 | if (!element.dataset) { |
| 121 | // If the browser is not compatible with HTMLElement.dataset, try to use getAttribute to get |
| 122 | const attrKey = 'data-' + key.replace(/([A-Z])/g, '-$1').toLowerCase(); |
| 123 | const dataset = element.getAttribute(attrKey); |
| 124 | if (dataset) { |
| 125 | return dataset; |
| 126 | } |
| 127 | return null; |
| 128 | } |
| 129 | return element.dataset[key]; |
| 130 | } |
| 131 | |
| 132 | export function stopPropagation(e: React.SyntheticEvent) { |
| 133 | e.stopPropagation(); |
no test coverage detected