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

fix(pro:search): empty input segment should be invalid #1494

Merged
Merged
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
4 changes: 2 additions & 2 deletions packages/pro/search/src/segments/createInputSegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { InputSearchField, Segment } from '../types'

export function createInputSegment(prefixCls: string, searchField: InputSearchField): Segment<string> {
export function createInputSegment(prefixCls: string, searchField: InputSearchField): Segment<string | undefined> {
const {
fieldConfig: { trim },
defaultValue,
Expand All @@ -19,7 +19,7 @@ export function createInputSegment(prefixCls: string, searchField: InputSearchFi
inputClassName: [inputClassName, `${prefixCls}-input-segment-input`],
placeholder: searchField.placeholder,
defaultValue,
parse: input => input,
parse: input => (input ? input : undefined),
format: value => (trim ? value?.trim() : value) ?? '',
}
}
Copy link

Choose a reason for hiding this comment

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

the code review

The code patch looks good. It appears that the goal is to make the input value type of the createInputSegment function to a string or undefined instead of just a string.

The changes check that the input value is not null or undefined before parsing and formatting it, and they also change the return type of the createInputSegment function to string or undefined. This should help prevent any bugs related to unexpected input values.

However, it is worth noting that the parse and format functions are still expecting a string value, so further checks may be necessary if other data types are being used. Additionally, it would be helpful to add more detailed comments to the code explaining what it does and why.