Skip to content

Commit 90f3a53

Browse files
authored
Merge pull request #11040 from marmelab/fix-save-button-story
[chore] Fix `<SaveButton>` _Dirty_ story
2 parents 63b6405 + 9c65803 commit 90f3a53

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/ra-ui-materialui/src/button/SaveButton.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { AdminContext } from '../AdminContext';
2323
import {
2424
AlwaysEnable,
2525
Basic,
26+
Dirty,
2627
ComplexForm,
2728
EnabledWhenFormIsPrefilled,
2829
} from './SaveButton.stories';
@@ -69,6 +70,15 @@ describe('<SaveButton />', () => {
6970
);
7071
});
7172

73+
it('should render an enabled button when the form is dirty', async () => {
74+
render(<Dirty />);
75+
await waitFor(() =>
76+
expect(screen.getByLabelText('ra.action.save')['disabled']).toEqual(
77+
false
78+
)
79+
);
80+
});
81+
7282
it('should render as submit type by default', async () => {
7383
render(<Basic />);
7484
await waitFor(() =>

packages/ra-ui-materialui/src/button/SaveButton.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ export const Basic = () => (
2626
);
2727

2828
const MakeFormChange = () => {
29-
const { setValue } = useFormContext();
29+
const {
30+
setValue,
31+
formState: { isReady },
32+
} = useFormContext();
3033
React.useEffect(() => {
34+
if (!isReady) return;
3135
setValue('name', 'test', { shouldDirty: true });
32-
}, [setValue]);
36+
}, [isReady, setValue]);
3337
return null;
3438
};
3539

0 commit comments

Comments
 (0)