File tree Expand file tree Collapse file tree 1 file changed +9
-13
lines changed
packages/components/details Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,6 @@ const { toggleAttribute } = require('../../common')
6
6
*/
7
7
8
8
module . exports = ( { scope = document } = { } ) => {
9
- // Does the browser support details component
10
- const nativeSupport =
11
- typeof document . createElement ( 'details' ) . open === 'boolean'
12
- if ( nativeSupport ) {
13
- return
14
- }
15
-
16
9
// Nodelist of all details elements
17
10
const allDetails = scope . querySelectorAll ( 'details' )
18
11
@@ -77,10 +70,13 @@ module.exports = ({ scope = document } = {}) => {
77
70
} )
78
71
}
79
72
80
- // Initialise details for any new details element
81
- if ( allDetails . length ) {
82
- allDetails . forEach ( ( element , index ) => {
83
- if ( ! element . hasAttribute ( 'nhsuk-polyfilled' ) ) initDetails ( element , index )
84
- } )
85
- }
73
+ allDetails . forEach ( ( element , index ) => {
74
+ // If there is native details support, we want to avoid running code to polyfill native behaviour.
75
+ const hasNativeDetails =
76
+ 'HTMLDetailsElement' in window && element instanceof HTMLDetailsElement
77
+
78
+ if ( ! hasNativeDetails && ! element . hasAttribute ( 'nhsuk-polyfilled' ) ) {
79
+ initDetails ( element , index )
80
+ }
81
+ } )
86
82
}
You can’t perform that action at this time.
0 commit comments