Skip to content

Commit ce01db5

Browse files
fix: only handle blur event for resizing viewport on iOS (#9393)
* fix: only handle blur event for resizing viewport on iOS * Add a testing story * fix lint --------- Co-authored-by: Robert Snow <snowystinger@gmail.com>
1 parent bd2bdf7 commit ce01db5

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

packages/@react-aria/utils/src/useViewportSize.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13+
import {isIOS} from './platform';
1314
import {useEffect, useState} from 'react';
1415
import {useIsSSR} from '@react-aria/ssr';
1516
import {willOpenKeyboard} from './keyboard';
@@ -65,7 +66,9 @@ export function useViewportSize(): ViewportSize {
6566

6667
updateSize(getViewportSize());
6768

68-
window.addEventListener('blur', onBlur, true);
69+
if (isIOS()) {
70+
window.addEventListener('blur', onBlur, true);
71+
}
6972

7073
if (!visualViewport) {
7174
window.addEventListener('resize', onResize);
@@ -75,7 +78,9 @@ export function useViewportSize(): ViewportSize {
7578

7679
return () => {
7780
cancelAnimationFrame(frame);
78-
window.removeEventListener('blur', onBlur, true);
81+
if (isIOS()) {
82+
window.removeEventListener('blur', onBlur, true);
83+
}
7984
if (!visualViewport) {
8085
window.removeEventListener('resize', onResize);
8186
} else {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2026 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {Meta} from '@storybook/react';
14+
import React from 'react';
15+
import {useViewportSize} from '@react-aria/utils';
16+
17+
export default {
18+
title: 'useViewportSize',
19+
component: Example
20+
} as Meta<typeof Example>;
21+
22+
export function Example() {
23+
const viewportSize = useViewportSize();
24+
25+
return (
26+
<div>
27+
{JSON.stringify(viewportSize)}
28+
<input />
29+
<div style={{height: '200vh'}} />
30+
</div>
31+
);
32+
}
33+
34+
Example.parameters = {
35+
description: {
36+
data: 'Clicking the input and then clicking outside should not cause the viewport size to change.'
37+
}
38+
};

0 commit comments

Comments
 (0)