({buttons})
| 537 | ` |
| 538 | |
| 539 | const Buttons: React.FC<React.PropsWithChildren<{buttons: DialogButtonProps[]}>> = ({buttons}) => { |
| 540 | const autoFocusRef = useProvidedRefOrCreate<HTMLButtonElement>(buttons.find(button => button.autoFocus)?.ref) |
| 541 | let autoFocusCount = 0 |
| 542 | const [hasRendered, setHasRendered] = useState(0) |
| 543 | useEffect(() => { |
| 544 | // hack to work around dialogs originating from other focus traps. |
| 545 | if (hasRendered === 1) { |
| 546 | autoFocusRef.current?.focus() |
| 547 | } else { |
| 548 | setHasRendered(hasRendered + 1) |
| 549 | } |
| 550 | }, [autoFocusRef, hasRendered]) |
| 551 | |
| 552 | return ( |
| 553 | <> |
| 554 | {buttons.map((dialogButtonProps, index) => { |
| 555 | const {content, buttonType = 'default', autoFocus = false, ...buttonProps} = dialogButtonProps |
| 556 | return ( |
| 557 | <Button |
| 558 | key={index} |
| 559 | {...buttonProps} |
| 560 | // 'normal' value is equivalent to 'default', this is used for backwards compatibility |
| 561 | variant={buttonType === 'normal' ? 'default' : buttonType} |
| 562 | ref={autoFocus && autoFocusCount === 0 ? (autoFocusCount++, autoFocusRef) : null} |
| 563 | > |
| 564 | {content} |
| 565 | </Button> |
| 566 | ) |
| 567 | })} |
| 568 | </> |
| 569 | ) |
| 570 | } |
| 571 | const DialogCloseButton = styled(Button)` |
| 572 | border-radius: 4px; |
| 573 | background: transparent; |
nothing calls this directly
no test coverage detected