Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/@react-aria/utils/src/useViewportSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* governing permissions and limitations under the License.
*/

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

updateSize(getViewportSize());

window.addEventListener('blur', onBlur, true);
if (isIOS()) {
window.addEventListener('blur', onBlur, true);
}

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

return () => {
cancelAnimationFrame(frame);
window.removeEventListener('blur', onBlur, true);
if (isIOS()) {
window.removeEventListener('blur', onBlur, true);
}
if (!visualViewport) {
window.removeEventListener('resize', onResize);
} else {
Expand Down
38 changes: 38 additions & 0 deletions packages/@react-aria/utils/stories/useViewportSize.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2026 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import {Meta} from '@storybook/react';
import React from 'react';
import {useViewportSize} from '@react-aria/utils';

export default {
title: 'useViewportSize',
component: Example
} as Meta<typeof Example>;

export function Example() {
const viewportSize = useViewportSize();

return (
<div>
{JSON.stringify(viewportSize)}
<input />
<div style={{height: '200vh'}} />
</div>
);
}

Example.parameters = {
description: {
data: 'Clicking the input and then clicking outside should not cause the viewport size to change.'
}
};