Skip to content

Commit

Permalink
Fix testing for support in hidden documents
Browse files Browse the repository at this point in the history
The `elementExpands()` feature test would incorrectly return false in browsers with native <details> support when the document or parent `<iframe>` was hidden (because `offsetHeight` and similar will always be 0).

Fixes #21
Closes #23
  • Loading branch information
javan committed Aug 13, 2019
1 parent e665d4d commit cd38a7d
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/support.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const element = document.createElement("details")
element.innerHTML = "<summary>a</summary>b"
element.setAttribute("style", "position: absolute; left: -9999px")
const elementIsNative = typeof HTMLDetailsElement != "undefined" && element instanceof HTMLDetailsElement

export default {
open: "open" in element && elementExpands(),
open: "open" in element || elementIsNative,
toggle: "ontoggle" in element
}

function elementExpands() {
(document.body || document.documentElement).appendChild(element)

const closedHeight = element.offsetHeight
element.open = true
const openedHeight = element.offsetHeight

element.parentNode.removeChild(element)
return closedHeight != openedHeight
}

0 comments on commit cd38a7d

Please sign in to comment.