Skip to content

Commit fed0734

Browse files
author
Alfonso Cerrato
committed
feat(WEB-821): Add onScreenChanged callback to widget
1 parent 8941427 commit fed0734

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ import * as typeformEmbed from "@typeform/embed";
5454

5555
const MyTypeform = () => {
5656
const typeformRef = useRef(null);
57-
57+
5858
useEffect(() => {
5959
typeformEmbed.makeWidget(typeformRef.current, 'https://form.typeform.com/to/MY_TYPEFORM_ID', {
6060
hideFooter: true,
6161
hideHeaders: true,
6262
opacity: 0,
6363
});
6464
}, [typeformRef]);
65-
65+
6666
return (
6767
<div ref={typeformRef} style={{ height: '100vh', width: '100%'}}></div>
6868
);
@@ -82,16 +82,17 @@ typeformEmbed.makeWidget(element, url, options)
8282
- **url**: typeform's URL (like: `https://admin.typeform.com/to/PlBzgL`)
8383
- **options**: Object with the optional parameters:
8484

85-
| option | description | values | default |
86-
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|---------|
87-
| opacity | You can make your typeform's background totally transparent, or opaque. (For example, to have a video as a background) | `Number` | 100 |
88-
| buttonText | The button text that appears on mobile in order to open the typeform. | `String` | "Start" |
89-
| hideScrollbars | Hide fixed scrollbars. | `Boolean` | false |
90-
| hideFooter | Hide typeform footer, that appears showing the progress bar and the navigation buttons. | `Boolean` | false |
91-
| hideHeaders | Hide typeform header, that appears when you have a Question group, or a long question that you need to scroll through to answer, like a Multiple Choice block. | `Boolean` | false |
92-
| onSubmit | Callback function that will be executed right after the typeform is successfully submitted. | `Function` | - |
93-
| onReady | Callback function that will be executed once the typeform is ready. | `Function` | - |
94-
| transferableUrlParameters | Parameters that we want to transfert from the URL to the Typeform as hidden fields | `Array` | [] |
85+
| option | description | values | default |
86+
|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|---------|
87+
| opacity | You can make your typeform's background totally transparent, or opaque. (For example, to have a video as a background) | `Number` | 100 |
88+
| buttonText | The button text that appears on mobile in order to open the typeform. | `String` | "Start" |
89+
| hideScrollbars | Hide fixed scrollbars. | `Boolean` | false |
90+
| hideFooter | Hide typeform footer, that appears showing the progress bar and the navigation buttons. | `Boolean` | false |
91+
| hideHeaders | Hide typeform header, that appears when you have a Question group, or a long question that you need to scroll through to answer, like a Multiple Choice block. | `Boolean` | false |
92+
| onSubmit | Callback function that will be executed right after the typeform is successfully submitted. | `Function` | - |
93+
| onReady | Callback function that will be executed once the typeform is ready. | `Function` | - |
94+
| onScreenChanged | Callback function that will be executed once the typeform's active screen changes. | `Function` | - |
95+
| transferableUrlParameters | Parameters that we want to transfert from the URL to the Typeform as hidden fields | `Array` | [] |
9596
#### Example:
9697

9798
```js

src/core/make-widget.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const defaultOptions = {
2424
hideScrollbars: false,
2525
disableTracking: false,
2626
transferableUrlParameters: [],
27-
onSubmit: noop
27+
onSubmit: noop,
28+
onScreenChanged: noop
2829
}
2930

3031
const queryStringKeys = {

src/core/views/widget.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class Widget extends Component {
129129
this.debouncedScroll = debounce(this.focusIframe, DEBOUNCE_WAIT, this)
130130
this.setIframeRef = this.setIframeRef.bind(this)
131131
this.sendFocusMessageToIframe = this.sendFocusMessageToIframe.bind(this)
132+
this.handleFormScreenChanged = this.handleFormScreenChanged.bind(this)
132133
}
133134

134135
componentDidMount () {
@@ -140,6 +141,7 @@ class Widget extends Component {
140141
window.addEventListener('welcome-screen-hidden', this.goFullScreen)
141142
window.addEventListener('redirect-after-submit', redirectToUrl)
142143
window.addEventListener('thank-you-screen-redirect', redirectToUrl)
144+
window.addEventListener('form-screen-changed', this.handleFormScreenChanged)
143145

144146
document.body.appendChild(this.fullScreenModalDiv)
145147
}
@@ -153,6 +155,7 @@ class Widget extends Component {
153155
window.removeEventListener('welcome-screen-hidden', this.goFullScreen)
154156
window.removeEventListener('redirect-after-submit', redirectToUrl)
155157
window.removeEventListener('thank-you-screen-redirect', redirectToUrl)
158+
window.removeEventListener('form-screen-changed', this.handleFormScreenChanged)
156159

157160
document.body.removeChild(this.fullScreenModalDiv)
158161
}
@@ -191,6 +194,12 @@ class Widget extends Component {
191194
})
192195
}
193196

197+
handleFormScreenChanged (event) {
198+
if (this.props.options.onScreenChanged) {
199+
this.props.options.onScreenChanged(event)
200+
}
201+
}
202+
194203
handleMessage (event) {
195204
broadcastMessage(this.embedId, event)
196205
}

0 commit comments

Comments
 (0)