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

[pickers] Remove the hasLeadingZeros property from FieldSection #10994

Merged
merged 4 commits into from
Nov 10, 2023
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
25 changes: 25 additions & 0 deletions docs/data/migration/migration-pickers-v6/migration-pickers-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ For example:

The same applies to `slotProps` and `componentsProps`.
:::

## Field components

### Replace the section `hasLeadingZeros` property

:::success
This only impacts you if you are using the `unstableFieldRef` prop to imperatively access the section object.
:::

The property `hasLeadingZeros` has been removed from the sections in favor of the more precise `hasLeadingZerosInFormat` and `hasLeadingZerosInInput` properties.
To keep the same behavior, you can replace it by `hasLeadingZerosInFormat`

```diff
const fieldRef = React.useRef<FieldRef<FieldSection>>(null);

React.useEffect(() => {
const firstSection = fieldRef.current!.getSections()[0]
- console.log(firstSection.hasLeadingZeros)
+ console.log(firstSection.hasLeadingZerosInFormat)
}, [])

return (
<DateField unstableFieldRef={fieldRef} />
);
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const COMMON_PROPERTIES = {
type: 'year',
modified: false,
format: 'YYYY',
hasLeadingZeros: true,
hasLeadingZerosInFormat: true,
maxLength: 4,
} as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ export const splitFormatIntoSections = <TDate>(
maxLength,
value: sectionValue,
placeholder: getSectionPlaceholder(utils, timezone, localeText, sectionConfig, token),
hasLeadingZeros: hasLeadingZerosInFormat,
hasLeadingZerosInFormat,
hasLeadingZerosInInput,
startSeparator: sections.length === 0 ? startSeparator : '',
Expand Down
6 changes: 0 additions & 6 deletions packages/x-date-pickers/src/models/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export interface FieldSection {
* Will determine if we should apply a digit-based editing or a letter-based editing.
*/
contentType: FieldSectionContentType;
/**
* If `true`, the value of this section is supposed to have leading zeroes when parsed by the date library.
* For example, the value `1` should be rendered as "01" instead of "1".
* @deprecated Will be removed in v7, use `hasLeadingZerosInFormat` instead.
*/
hasLeadingZeros: boolean;
/**
* If `true`, the value of this section is supposed to have leading zeroes when parsed by the date library.
* For example, the value `1` should be rendered as "01" instead of "1".
Expand Down