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

[DateRangePicker] Fix name prop propagation regression #13821

Merged
merged 3 commits into from
Jul 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ describe('<DesktopDateRangePicker />', () => {

expect(input.parentElement).to.have.class('Mui-focused');
});

it('should render the input with a given `name` when `SingleInputDateRangeField` is used', () => {
// Test with v7 input
const v7Response = render(
<DesktopDateRangePicker
name="test"
enableAccessibleFieldDOMStructure
slots={{ field: SingleInputDateRangeField }}
/>,
);
expect(screen.getByRole<HTMLInputElement>('textbox', { hidden: true }).name).to.equal('test');

v7Response.unmount();

// Test with v6 input
render(<DesktopDateRangePicker name="test" slots={{ field: SingleInputDateRangeField }} />);
expect(screen.getByRole<HTMLInputElement>('textbox').name).to.equal('test');
});
});

describe('Component slot: Popper', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,31 @@ import {
getFieldSectionsContainer,
} from 'test/utils/pickers';
import { DateRange } from '@mui/x-date-pickers-pro/models';
import { SingleInputDateRangeField } from '@mui/x-date-pickers-pro/SingleInputDateRangeField';

describe('<MobileDateRangePicker />', () => {
const { render } = createPickerRenderer({ clock: 'fake' });

describe('Field slot: SingleInputDateRangeField', () => {
it('should render the input with a given `name` when `SingleInputDateRangeField` is used', () => {
// Test with v7 input
const v7Response = render(
<MobileDateRangePicker
name="test"
enableAccessibleFieldDOMStructure
slots={{ field: SingleInputDateRangeField }}
/>,
);
expect(screen.getByRole<HTMLInputElement>('textbox', { hidden: true }).name).to.equal('test');

v7Response.unmount();

// Test with v6 input
render(<MobileDateRangePicker name="test" slots={{ field: SingleInputDateRangeField }} />);
expect(screen.getByRole<HTMLInputElement>('textbox').name).to.equal('test');
});
});

describe('picker state', () => {
it('should open when focusing the start input', () => {
const onOpen = spy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const useDesktopRangePicker = <
timezone,
autoFocus: autoFocus && !props.open,
ref: fieldContainerRef,
...(inputRef ? { inputRef, name } : {}),
...(fieldType === 'single-input' ? { inputRef, name } : {}),
},
ownerState: props,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useMobileRangePicker = <
selectedSections,
onSelectedSectionsChange,
timezone,
...(inputRef ? { inputRef, name } : {}),
...(fieldType === 'single-input' ? { inputRef, name } : {}),
},
ownerState: props,
});
Expand Down