Skip to content

Commit f56df55

Browse files
Merge pull request #2450 from nhsuk/iframe-resize
Resize example iframes when contents changes size
2 parents 4f08c88 + c2a9853 commit f56df55

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# NHS digital service manual Changelog
22

3+
## Unreleased
4+
5+
:wrench: **Maintenance**
6+
7+
- Resize example iframes when contents changes size
8+
39
## 8.7.0 - 17 February 2026
410

511
:new: **New features**

app/javascripts/design-example.mjs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class DesignExample extends Component {
2020
this.closeButtons = this.$root.querySelectorAll('.app-button--close')
2121
this.copyButtons = this.$root.querySelectorAll('.app-button--copy')
2222
this.iframe = this.$root.querySelector('iframe')
23+
this.state = { isMouseDown: false }
2324

2425
this.bindEvents()
2526

@@ -88,19 +89,21 @@ export class DesignExample extends Component {
8889
}
8990

9091
if (this.iframe) {
91-
initialize(
92-
{
93-
// Prevent resize when iframe has mouse cursor
94-
// e.g. When resizing manually using handle
95-
onBeforeIframeResize({ interactionState }) {
96-
return !interactionState.isHovered
97-
}
98-
},
99-
this.iframe
100-
)
92+
const { iframe, state } = this
93+
94+
iframe.addEventListener('mousedown', () => (state.isMouseDown = true))
95+
iframe.addEventListener('mouseup', () => (state.isMouseDown = false))
96+
97+
initialize({ onBeforeIframeResize: () => this.isResizeAllowed() }, iframe)
10198
}
10299
}
103100

101+
isResizeAllowed() {
102+
// Prevent resize when iframe has mouse down
103+
// e.g. When resizing manually using handle
104+
return !this.state.isMouseDown
105+
}
106+
104107
handleTabClick($tabLink) {
105108
const $tabParent = $tabLink.parentElement
106109
const index = $tabParent.dataset.index

0 commit comments

Comments
 (0)