Skip to content

Commit

Permalink
fix: fix webchat not resizing properly on keyboard blur
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbasten17 committed Sep 19, 2024
1 parent 2e6cfb8 commit 4dbb311
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const useWebchatResizer = host => {
const keyboardOffset =
(window.visualViewport && window.visualViewport.height) ||
window.innerHeight

let newWebchatPercentualHeight = keyboardOffset / webchatHeight
newWebchatPercentualHeight =

Check warning on line 18 in packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
Math.round(newWebchatPercentualHeight * 100 * 100) / 100 // Two decimal places
Expand All @@ -29,16 +28,23 @@ export const useWebchatResizer = host => {
) {
const newWebchatPercentualHeight = `${calculateNewWebchatElementHeight()}%`
webchatRef.current.style.height = newWebchatPercentualHeight

Check warning on line 30 in packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts#L29-L30

Added lines #L29 - L30 were not covered by tests

const newChatAreaHeight = `${webchatRef.current.clientHeight - headerRef.current.clientHeight - inputPanelRef.current.clientHeight}px`

Check warning on line 32 in packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts#L32

Added line #L32 was not covered by tests

chatAreaRef.current.style.height = newChatAreaHeight
scrollToBottom()

Check warning on line 35 in packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts#L34-L35

Added lines #L34 - L35 were not covered by tests
}
}

const handleKeyboardHidden = () => {
if (webchatRef.current && chatAreaRef.current) {
if (
webchatRef.current &&
chatAreaRef.current &&
inputPanelRef.current &&
headerRef.current
) {
webchatRef.current.style.height = '100%'
chatAreaRef.current.style.height = '100%'
chatAreaRef.current.style.height = `${webchatRef.current.clientHeight - headerRef.current.clientHeight - inputPanelRef.current.clientHeight}px`

Check warning on line 47 in packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-react/src/webchat/hooks/use-webchat-resizer.ts#L46-L47

Added lines #L46 - L47 were not covered by tests
}
}

Expand Down

0 comments on commit 4dbb311

Please sign in to comment.