import * as React from 'react'; import { MessageBar, MessageBarType, Toggle, Text, mergeStyles } from '@fluentui/react'; import { useBoolean } from '@fluentui/react-hooks'; const wrapperClass = mergeStyles({ '> *:not(:last-child)': { marginBottom: '1.5em' }, '> * > *:not(:last-child)': { marginBottom: '0.5em' }, }); export const MessageBarNoDelayExample: React.FunctionComponent = () => { const [showAlert, { toggle: toggleShowAlert }] = useBoolean(false); const [showStatus, { toggle: toggleShowStatus }] = useBoolean(false); return (
By default, MessageBar renders its content within an internal live region after a short delay to help ensure it's announced by screen readers. You can disable this behavior (while still ensuring the message is read by screen readers) by setting the delayedRender prop to false and setting up the MessageBar in one of the following ways.
Option 1: If the MessageBar uses role="alert", the content should be read on insertion. This role will be set automatically if messageBarType is error,{' '} blocked, or severeWarning. {showAlert && ( This is an error message. )}
Option 2: Wrap the whole MessageBar in a {'
'} which is always rendered, and ensure the MessageBar is rendered either conditionally or with a delay. You should also set{' '} role="none" on the MessageBar itself to prevent nested status regions. {/* IMPORTANT: This wrapper div must always be rendered */}
{showStatus && ( This is a status message. )}
); };