From 4134497d6d3a4ae3fe335fe16e64d78fed40063d Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Tue, 29 Oct 2024 14:56:56 +0100 Subject: [PATCH 1/2] [docs] Apply the new DX to the `Autocomplete` Field demo (#15165) --- .../PickerWithJoyField.tsx.preview | 12 ---- .../MaterialDatePicker.js} | 41 +++++++----- .../MaterialDatePicker.tsx} | 65 ++++++++++--------- .../MaterialDatePicker.tsx.preview} | 0 .../date-pickers/custom-field/custom-field.md | 2 +- 5 files changed, 60 insertions(+), 60 deletions(-) delete mode 100644 docs/data/date-pickers/custom-field/PickerWithJoyField.tsx.preview rename docs/data/date-pickers/custom-field/{PickerWithAutocompleteField.js => behavior-autocomplete/MaterialDatePicker.js} (79%) rename docs/data/date-pickers/custom-field/{PickerWithAutocompleteField.tsx => behavior-autocomplete/MaterialDatePicker.tsx} (75%) rename docs/data/date-pickers/custom-field/{PickerWithAutocompleteField.tsx.preview => behavior-autocomplete/MaterialDatePicker.tsx.preview} (100%) diff --git a/docs/data/date-pickers/custom-field/PickerWithJoyField.tsx.preview b/docs/data/date-pickers/custom-field/PickerWithJoyField.tsx.preview deleted file mode 100644 index cff735f8a7af0..0000000000000 --- a/docs/data/date-pickers/custom-field/PickerWithJoyField.tsx.preview +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/docs/data/date-pickers/custom-field/PickerWithAutocompleteField.js b/docs/data/date-pickers/custom-field/behavior-autocomplete/MaterialDatePicker.js similarity index 79% rename from docs/data/date-pickers/custom-field/PickerWithAutocompleteField.js rename to docs/data/date-pickers/custom-field/behavior-autocomplete/MaterialDatePicker.js index ea7512ace1590..0e849ab1228c0 100644 --- a/docs/data/date-pickers/custom-field/PickerWithAutocompleteField.js +++ b/docs/data/date-pickers/custom-field/behavior-autocomplete/MaterialDatePicker.js @@ -6,19 +6,31 @@ import Stack from '@mui/material/Stack'; import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; +import { useSplitFieldProps } from '@mui/x-date-pickers/hooks'; +import { useValidation, validateDate } from '@mui/x-date-pickers/validation'; function AutocompleteField(props) { + const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date'); + const { value, timezone, onChange } = internalProps; const { + InputProps, + slotProps, + slots, + ownerState, label, - disabled, - readOnly, - id, - value, - onChange, - InputProps: { ref, startAdornment, endAdornment } = {}, - inputProps, + focused, + name, options = [], - } = props; + inputProps, + ...other + } = forwardedProps; + + const { hasValidationError } = useValidation({ + validator: validateDate, + value, + timezone, + props: internalProps, + }); const mergeAdornments = (...adornments) => { const nonNullAdornments = adornments.filter((el) => el != null); @@ -41,25 +53,24 @@ function AutocompleteField(props) { return ( ( , - BaseSingleInputFieldProps< - Dayjs | null, - Dayjs, - FieldSection, - true, - DateValidationError - > { +interface AutocompleteFieldProps extends DatePickerFieldProps { /** * @typescript-to-proptypes-ignore */ options?: Dayjs[]; } -function AutocompleteField(props: AutoCompleteFieldProps) { +function AutocompleteField(props: AutocompleteFieldProps) { + const { internalProps, forwardedProps } = useSplitFieldProps(props, 'date'); + const { value, timezone, onChange } = internalProps; const { + InputProps, + slotProps, + slots, + ownerState, label, - disabled, - readOnly, - id, - value, - onChange, - InputProps: { ref, startAdornment, endAdornment } = {}, - inputProps, + focused, + name, options = [], - } = props; + inputProps, + ...other + } = forwardedProps; + + const { hasValidationError } = useValidation({ + validator: validateDate, + value, + timezone, + props: internalProps, + }); const mergeAdornments = (...adornments: React.ReactNode[]) => { const nonNullAdornments = adornments.filter((el) => el != null); @@ -62,25 +64,24 @@ function AutocompleteField(props: AutoCompleteFieldProps) { return ( ( + !optionsLookup[date.startOf('day').toISOString()]} @@ -138,7 +139,7 @@ function AutocompleteDatePicker(props: AutocompleteDatePickerProps) { const today = dayjs().startOf('day'); -export default function PickerWithAutocompleteField() { +export default function MaterialDatePicker() { return ( Date: Tue, 29 Oct 2024 15:30:45 +0100 Subject: [PATCH 2/2] [DataGrid] Fix scroll jump when holding down arrow keys (#15164) --- .../virtualization/GridVirtualScrollbar.tsx | 4 +-- .../hooks/features/scroll/useGridScroll.ts | 26 +++---------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/x-data-grid/src/components/virtualization/GridVirtualScrollbar.tsx b/packages/x-data-grid/src/components/virtualization/GridVirtualScrollbar.tsx index c832d14145530..42b3fb00e8c75 100644 --- a/packages/x-data-grid/src/components/virtualization/GridVirtualScrollbar.tsx +++ b/packages/x-data-grid/src/components/virtualization/GridVirtualScrollbar.tsx @@ -100,6 +100,8 @@ const GridVirtualScrollbar = React.forwardRef { diff --git a/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts b/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts index 067d013bb0065..edd401c720900 100644 --- a/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts +++ b/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts @@ -60,8 +60,6 @@ export const useGridScroll = ( const logger = useGridLogger(apiRef, 'useGridScroll'); const colRef = apiRef.current.columnHeadersContainerRef; const virtualScrollerRef = apiRef.current.virtualScrollerRef!; - const virtualScrollbarHorizontalRef = apiRef.current.virtualScrollbarHorizontalRef!; - const virtualScrollbarVerticalRef = apiRef.current.virtualScrollbarVerticalRef!; const visibleSortedRows = useGridSelector(apiRef, gridExpandedSortedRowEntriesSelector); const scrollToIndexes = React.useCallback( @@ -156,37 +154,19 @@ export const useGridScroll = ( const scroll = React.useCallback( (params: Partial) => { - if ( - virtualScrollerRef.current && - virtualScrollbarHorizontalRef.current && - params.left !== undefined && - colRef.current - ) { + if (virtualScrollerRef.current && params.left !== undefined && colRef.current) { const direction = isRtl ? -1 : 1; colRef.current.scrollLeft = params.left; virtualScrollerRef.current.scrollLeft = direction * params.left; - virtualScrollbarHorizontalRef.current.scrollLeft = direction * params.left; logger.debug(`Scrolling left: ${params.left}`); } - if ( - virtualScrollerRef.current && - virtualScrollbarVerticalRef.current && - params.top !== undefined - ) { + if (virtualScrollerRef.current && params.top !== undefined) { virtualScrollerRef.current.scrollTop = params.top; - virtualScrollbarVerticalRef.current.scrollTop = params.top; logger.debug(`Scrolling top: ${params.top}`); } logger.debug(`Scrolling, updating container, and viewport`); }, - [ - virtualScrollerRef, - virtualScrollbarHorizontalRef, - virtualScrollbarVerticalRef, - isRtl, - colRef, - logger, - ], + [virtualScrollerRef, isRtl, colRef, logger], ); const getScrollPosition = React.useCallback(() => {