diff --git a/docs/reference/generated/alert-dialog-close.json b/docs/reference/generated/alert-dialog-close.json index e2225191d2..05a6096969 100644 --- a/docs/reference/generated/alert-dialog-close.json +++ b/docs/reference/generated/alert-dialog-close.json @@ -11,6 +11,10 @@ "description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render." } }, - "dataAttributes": {}, + "dataAttributes": { + "data-disabled": { + "description": "Present when the button is disabled." + } + }, "cssVariables": {} } diff --git a/docs/reference/generated/alert-dialog-trigger.json b/docs/reference/generated/alert-dialog-trigger.json index bf9f2e0457..c101b3a29c 100644 --- a/docs/reference/generated/alert-dialog-trigger.json +++ b/docs/reference/generated/alert-dialog-trigger.json @@ -14,6 +14,9 @@ "dataAttributes": { "data-popup-open": { "description": "Present when the corresponding dialog is open." + }, + "data-disabled": { + "description": "Present when the trigger is disabled." } }, "cssVariables": {} diff --git a/docs/reference/generated/dialog-close.json b/docs/reference/generated/dialog-close.json index 53fde94f99..663e2c2bde 100644 --- a/docs/reference/generated/dialog-close.json +++ b/docs/reference/generated/dialog-close.json @@ -11,6 +11,10 @@ "description": "Allows you to replace the component’s HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render." } }, - "dataAttributes": {}, + "dataAttributes": { + "data-disabled": { + "description": "Present when the button is disabled." + } + }, "cssVariables": {} } diff --git a/docs/reference/generated/dialog-trigger.json b/docs/reference/generated/dialog-trigger.json index 06a0a8aef3..4da75624ce 100644 --- a/docs/reference/generated/dialog-trigger.json +++ b/docs/reference/generated/dialog-trigger.json @@ -14,6 +14,9 @@ "dataAttributes": { "data-popup-open": { "description": "Present when the corresponding dialog is open." + }, + "data-disabled": { + "description": "Present when the trigger is disabled." } }, "cssVariables": {} diff --git a/packages/react/src/alert-dialog/close/AlertDialogClose.test.tsx b/packages/react/src/alert-dialog/close/AlertDialogClose.test.tsx index 1158b16ccc..b66944db8c 100644 --- a/packages/react/src/alert-dialog/close/AlertDialogClose.test.tsx +++ b/packages/react/src/alert-dialog/close/AlertDialogClose.test.tsx @@ -1,5 +1,8 @@ import * as React from 'react'; +import { expect } from 'chai'; +import { spy } from 'sinon'; import { AlertDialog } from '@base-ui-components/react/alert-dialog'; +import { screen } from '@mui/internal-test-utils'; import { createRenderer, describeConformance } from '#test-utils'; describe('', () => { @@ -18,4 +21,69 @@ describe('', () => { ); }, })); + + describe('prop: disabled', () => { + it('disables the button', async () => { + const handleOpenChange = spy(); + + const { user } = await render( + + Open + + + Close + + + , + ); + + expect(handleOpenChange.callCount).to.equal(0); + + const openButton = screen.getByText('Open'); + await user.click(openButton); + + expect(handleOpenChange.callCount).to.equal(1); + expect(handleOpenChange.firstCall.args[0]).to.equal(true); + + const closeButton = screen.getByText('Close'); + expect(closeButton).to.have.attribute('disabled'); + expect(closeButton).to.have.attribute('data-disabled'); + await user.click(closeButton); + + expect(handleOpenChange.callCount).to.equal(1); + }); + + it('custom element', async () => { + const handleOpenChange = spy(); + + const { user } = await render( + + Open + + + }> + Close + + + + , + ); + + expect(handleOpenChange.callCount).to.equal(0); + + const openButton = screen.getByText('Open'); + await user.click(openButton); + + expect(handleOpenChange.callCount).to.equal(1); + expect(handleOpenChange.firstCall.args[0]).to.equal(true); + + const closeButton = screen.getByText('Close'); + expect(closeButton).to.not.have.attribute('disabled'); + expect(closeButton).to.have.attribute('data-disabled'); + expect(closeButton).to.have.attribute('aria-disabled', 'true'); + await user.click(closeButton); + + expect(handleOpenChange.callCount).to.equal(1); + }); + }); }); diff --git a/packages/react/src/alert-dialog/close/AlertDialogClose.tsx b/packages/react/src/alert-dialog/close/AlertDialogClose.tsx index 27a8d2c791..607c340919 100644 --- a/packages/react/src/alert-dialog/close/AlertDialogClose.tsx +++ b/packages/react/src/alert-dialog/close/AlertDialogClose.tsx @@ -6,8 +6,6 @@ import { useDialogClose } from '../../dialog/close/useDialogClose'; import { useComponentRenderer } from '../../utils/useComponentRenderer'; import type { BaseUIComponentProps } from '../../utils/types'; -const state = {}; - /** * A button that closes the alert dialog. * Renders a `