Pular para o conteúdo

Unstable_TrapFocus API

Documentação da API para o componente React Unstable_TrapFocus . Aprenda sobre as propriedades disponíveis e a API CSS.

Importação

import Unstable_TrapFocus from '@mui/core/Unstable_TrapFocus';
// ou
import { Unstable_TrapFocus } from '@mui/core';
Você pode aprender sobre a diferença lendo este guia sobre como minimizar o tamanho do pacote.

Utility component that locks focus inside the component.

Propriedades

NomeTipoPadrãoDescrição
open*boolfalse
If true, focus is locked.
childrenelement
A single child content element.
⚠️ Needs to be able to hold a ref.
disableAutoFocusboolfalse
If true, the trap focus will not automatically shift focus to itself when it opens, and replace it to the last focused element when it closes. This also works correctly with any trap focus children that have the disableAutoFocus prop.
Generally this should never be set to true as it makes the trap focus less accessible to assistive technologies, like screen readers.
disableEnforceFocusboolfalse
If true, the trap focus will not prevent focus from leaving the trap focus while open.
Generally this should never be set to true as it makes the trap focus less accessible to assistive technologies, like screen readers.
disableRestoreFocusboolfalse
If true, the trap focus will not restore focus to previously focused element once trap focus is hidden.
getTabbablefunc
Returns an array of ordered tabbable nodes (i.e. in tab order) within the root. For instance, you can provide the "tabbable" npm dependency.

Signature:
function(root: HTMLElement) => void
isEnabledfuncfunction defaultIsEnabled() { return true; }
This prop extends the open prop. It allows to toggle the open state without having to wait for a rerender when changing the open prop. This prop should be memoized. It can be used to support multiple trap focus mounted at the same time.

O componente não pode manipular ref.

Demonstrações