{/* Copyright 2025 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 {Layout} from '../../src/Layout'; export default Layout; import docs from 'docs:@react-aria/visually-hidden'; import {FunctionAPI} from '../../src/FunctionAPI';
export const section = 'Utilities';
VisuallyHidden
{docs.exports.VisuallyHidden.description}
VisuallyHidden is positioned absolutely, so it needs a positioned ancestor. Otherwise, it will be positioned relative to the nearest positioned ancestor, which may be the body, causing undesired scroll bars to appear.
<label style={{position: 'relative'}}>
<VisuallyHidden>
<input type="checkbox" />
</VisuallyHidden>
<span>Subscribe to our newsletter</span>
</label>In order to allow additional rendering flexibility, the useVisuallyHidden hook can be
used in custom components instead of the VisuallyHidden component. It supports the same
options as the component, and returns props to spread onto the element that should be hidden.
import {useVisuallyHidden} from '@react-aria/visually-hidden';
let {visuallyHiddenProps} = useVisuallyHidden();
<div {...visuallyHiddenProps}>I am hidden</div>{/* not implemented yet /} {/ ## Example
See useRadioGroup and useCheckbox
for examples of using VisuallyHidden to hide native form elements visually. */}