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

[fields] Allow empty textField slot placeholder value #13148

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -138,18 +138,48 @@ describe('<DesktopDatePicker /> - Field', () => {
Component: DesktopDatePicker,
});

it('should allow to override the placeholder (v6 only)', () => {
renderWithProps({
enableAccessibleFieldDOMStructure: false,
slotProps: {
textField: {
placeholder: 'Custom placeholder',
describe('Placeholder override (v6 only)', () => {
arthurbalduini marked this conversation as resolved.
Show resolved Hide resolved
it('should allow to override the placeholder', () => {
renderWithProps({
enableAccessibleFieldDOMStructure: false,
slotProps: {
textField: {
placeholder: 'Custom placeholder',
},
},
},
});

const input = getTextbox();
expectFieldPlaceholderV6(input, 'Custom placeholder');
});

const input = getTextbox();
expectFieldPlaceholderV6(input, 'Custom placeholder');
it('should render blank placeholder when prop is an empty string', () => {
renderWithProps({
enableAccessibleFieldDOMStructure: false,
slotProps: {
textField: {
placeholder: '',
},
},
});

const input = getTextbox();
expectFieldPlaceholderV6(input, '');
});

it('should render blank placeholder when prop is undefined', () => {
renderWithProps({
enableAccessibleFieldDOMStructure: false,
slotProps: {
textField: {
placeholder: undefined,
},
},
});

const input = getTextbox();
expectFieldPlaceholderV6(input, '');
});
arthurbalduini marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
});

const placeholder = React.useMemo(() => {
if (inPlaceholder) {
return inPlaceholder;
if (inPlaceholder !== undefined) {
return inPlaceholder ?? '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried testing Flavien's suggestion?
I think that with it we could remove the ?? '' here. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And remove params.forwardedProps from the deps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 🙈
Done in d9d4964 and 78007e0

}

return fieldValueManager.getV6InputValueFromSections(
Expand All @@ -400,6 +400,7 @@ export const useFieldV6TextField: UseFieldTextField<false> = (params) => {
isRTL,
);
}, [
params.forwardedProps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could force the placeholder to be recalculated more often than we'd want. 🙈

inPlaceholder,
fieldValueManager,
getSectionsFromValue,
Expand Down