Skip to content

Commit

Permalink
[DateRangePicker] Fix name prop propagation regression (mui#13821)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored and DungTiger committed Jul 23, 2024
1 parent f25c3dc commit 8b83e69
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
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

0 comments on commit 8b83e69

Please sign in to comment.