(props: DialogTriggerProps)
| 79 | * A DialogTrigger opens a dialog when a trigger element is pressed. |
| 80 | */ |
| 81 | export function DialogTrigger(props: DialogTriggerProps): JSX.Element | null { |
| 82 | // Use useMenuTriggerState instead of useOverlayTriggerState in case a menu is embedded in the dialog. |
| 83 | // This is needed to handle submenus. |
| 84 | let state = useMenuTriggerState(props); |
| 85 | |
| 86 | let buttonRef = useRef<HTMLButtonElement>(null); |
| 87 | let {triggerProps, overlayProps} = useOverlayTrigger({type: 'dialog'}, state, buttonRef); |
| 88 | |
| 89 | // Label dialog by the trigger as a fallback if there is no title slot. |
| 90 | // This is done in RAC instead of hooks because otherwise we cannot distinguish |
| 91 | // between context and props. Normally aria-labelledby overrides the title |
| 92 | // but when sent by context we want the title to win. |
| 93 | // oxlint-disable-next-line react/react-compiler |
| 94 | triggerProps.id = useId(); |
| 95 | // oxlint-disable-next-line react/react-compiler |
| 96 | overlayProps['aria-labelledby'] = triggerProps.id; |
| 97 | |
| 98 | // If within a collection (e.g. Tabs), render nothing. |
| 99 | // Not using createHideableComponent for this because that also creates a forwardRef. |
| 100 | let isHidden = useIsHidden(); |
| 101 | if (isHidden) { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | return ( |
| 106 | <Provider |
| 107 | values={[ |
| 108 | [OverlayTriggerStateContext, state], |
| 109 | [RootMenuTriggerStateContext, state], |
| 110 | [DialogContext, overlayProps], |
| 111 | [ |
| 112 | PopoverContext, |
| 113 | { |
| 114 | trigger: 'DialogTrigger', |
| 115 | triggerRef: buttonRef, |
| 116 | id: overlayProps.id, |
| 117 | 'aria-labelledby': overlayProps['aria-labelledby'] |
| 118 | } |
| 119 | ] |
| 120 | ]}> |
| 121 | <PressResponder {...triggerProps} ref={buttonRef} isPressed={state.isOpen}> |
| 122 | {props.children} |
| 123 | </PressResponder> |
| 124 | </Provider> |
| 125 | ); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * A dialog is an overlay shown above other content in an application. |
nothing calls this directly
no test coverage detected