Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SaveButton renders disabled if Form is pristine. #4773

Merged
merged 7 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cypress/integration/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,29 @@ describe('Create Page', () => {
});

it('should show rich text input error message when form is submitted', () => {
const values = [
{
type: 'input',
name: 'title',
value: 'Test title',
},
];
CreatePage.setValues(values);
CreatePage.submit();
cy.get(CreatePage.elements.richTextInputError)
.should('exist')
.contains('Required');
});

it('should not show rich text input error message when form is submitted and input is filled with text', () => {
const values = [
{
type: 'input',
name: 'title',
value: 'Test title',
},
];
CreatePage.setValues(values);
CreatePage.submit();
cy.get(CreatePage.elements.richTextInputError)
.should('exist')
Expand Down
11 changes: 11 additions & 0 deletions packages/ra-ui-materialui/src/button/SaveButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ describe('<SaveButton />', () => {
spy.mockRestore();
});

it('should render a disabled button', () => {
const { getByLabelText } = render(
<TestContext>
<ThemeProvider theme={theme}>
<SaveButton pristine={true} />
</ThemeProvider>
</TestContext>
);
expect(getByLabelText('ra.action.save')['disabled']).toEqual(true);
});

it('should render as submit type when submitOnEnter is true', () => {
const { getByLabelText } = render(
<TestContext>
Expand Down
2 changes: 2 additions & 0 deletions packages/ra-ui-materialui/src/button/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SaveButton: FC<SaveButtonProps> = props => {
classes: classesOverride,
invalid,
label = 'ra.action.save',
disabled,
pristine,
redirect,
saving,
Expand Down Expand Up @@ -79,6 +80,7 @@ const SaveButton: FC<SaveButtonProps> = props => {
onClick={handleClick}
color={saving ? 'default' : 'primary'}
aria-label={displayedLabel}
disabled={disabled || pristine}
{...sanitizeButtonRestProps(rest)}
>
{saving ? (
Expand Down