File tree Expand file tree Collapse file tree
packages/@react-aria/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 * governing permissions and limitations under the License.
1111 */
1212
13+ import { isIOS } from './platform' ;
1314import { useEffect , useState } from 'react' ;
1415import { useIsSSR } from '@react-aria/ssr' ;
1516import { 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 {
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments