6.8 C
Canberra
Wednesday, July 22, 2026

javascript – iOS keyboard breaks web page structure when opened


I’m utilizing Vite + React + Bootstrap. That is my code:

componentDidMount() {
    this.updateAppHeight();
    if (window.visualViewport) {
        window.visualViewport.addEventListener('resize', this.updateAppHeight);
        window.visualViewport.addEventListener('scroll', this.updateAppHeight);
    } else {
        window.addEventListener('resize', this.updateAppHeight);
    }
}

componentWillUnmount() {
    if (window.visualViewport) {
        window.visualViewport.removeEventListener('resize', this.updateAppHeight);
        window.visualViewport.removeEventListener('scroll', this.updateAppHeight);
    } else {
        window.removeEventListener('resize', this.updateAppHeight);
    }
}

updateAppHeight = () => {
    const top = window.visualViewport
        ? `${window.visualViewport.top}px`
        : `${window.innerHeight}px`;
    doc.documentElement.type.setProperty('--app-height', top);
};

render() {
    return (
        

{this.renderMessages(this.state.messages)}

{ e.preventDefault(); this.checkAndSend(); }}>

...

); }

So there’s a scrollable message half and a enter bar that is fastened on the backside. I used dvh as the peak of this div first, however that solely works on Android. iOS doesn’t correctly replace it when the keyboard opens. So I attempted this repair, utilizing the viewport API to manually resize the div.

Now this works nicely apart from one bizarre problem on iOS I can not wrap my head round. When the keyboard opens, now the window will get moved up by the house the keyboard takes however get’s resized after that leaving the highest of this message half out of the display and the enter bar floating above a white empty house between the keyboard and the enter bar thats precisely the peak of the keyboard.

If I scroll up previous that “white field” every little thing aligns completely and it appears to be like okay. However for some motive iOS forces this web page to maneuver out of body, it doesn’t matter what.

How do I stop this? There should be a extra elegant answer however I couldn’t discover something anyplace.

It is my first query, please be good. Additionally thanks upfront!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles