Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default () => (
| optionRender | Custom rendering options | (oriOption: FlattenOptionData\<BaseOptionType\> , info: { index: number }) => React.ReactNode | - |
| labelRender | Custom rendering label | (props: LabelInValueType) => React.ReactNode | - |
| maxCount | The max number of items can be selected | number | - |
| inputProps | props passed to the internal input element | React.InputHTMLAttributes<HTMLInputElement> | - |

### Methods

Expand Down
7 changes: 5 additions & 2 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ export interface BaseSelectPrivateProps {
export type BaseSelectPropsWithoutPrivate = Omit<BaseSelectProps, keyof BaseSelectPrivateProps>;

export interface BaseSelectProps
extends
BaseSelectPrivateProps,
extends BaseSelectPrivateProps,
React.AriaAttributes,
Pick<React.HTMLAttributes<HTMLElement>, 'role'> {
// Style
Expand Down Expand Up @@ -229,6 +228,10 @@ export interface BaseSelectProps

// >>> Components
components?: ComponentsConfig;

// >>> Input
/** Props passed to the internal input element */
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

已经有 components 可以自定义子组件,inputProps 有点多余了。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

可以components.input = Input 。我去回复issue吧

}

export const isMultiple = (mode: Mode) => mode === 'tags' || mode === 'multiple';
Expand Down
8 changes: 7 additions & 1 deletion src/SelectInput/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ export interface SharedContentProps {
}

const SelectContent = React.forwardRef<HTMLInputElement>(function SelectContent(_, ref) {
const { multiple, onInputKeyDown, tabIndex } = useSelectInputContext();
const {
multiple,
onInputKeyDown,
tabIndex,
inputProps: userInputProps,
} = useSelectInputContext();
const baseProps = useBaseProps();
const { showSearch } = baseProps;

const ariaProps = pickAttrs(baseProps, { aria: true });

const sharedInputProps: SharedContentProps['inputProps'] = {
...ariaProps,
...userInputProps,
onKeyDown: onInputKeyDown,
readOnly: !showSearch,
tabIndex,
Expand Down
4 changes: 4 additions & 0 deletions src/SelectInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface InputProps {
syncWidth?: boolean;
/** autoComplete for input */
autoComplete?: string;
/** Props passed to the internal input element */
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
}

const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
Expand All @@ -33,6 +35,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
value,
className,
autoComplete,
inputProps,
...restProps
} = props;
const {
Expand Down Expand Up @@ -164,6 +167,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
id,
type: mode === 'combobox' ? 'text' : 'search',
...restProps,
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
Comment on lines +170 to 173
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The style and className properties from inputProps are currently overwritten by the component's explicit assignments that follow the spread. To ensure user-provided styles and classes are applied, they should be merged. Note that className also needs to be merged into the inputCls definition (around line 54), though that line is outside the current diff hunk.

Suggested change
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
...inputProps,
ref: inputRef as React.Ref<HTMLInputElement>,
style: {
...styles?.input,
...inputProps?.style,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

暂时不考虑这个style问题,应该统一由styles处理

Expand Down
3 changes: 3 additions & 0 deletions src/SelectInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
focused?: boolean;
components: ComponentsConfig;
children?: React.ReactElement;
/** Props passed to the internal input element */
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The inputProps prop added to the interface should also be destructured in the SelectInput component body (around line 76). Currently, it is not destructured, which means it remains in restProps and is subsequently included in domProps. This leads to inputProps being passed as a DOM attribute to the wrapper div element at line 261, which will trigger a React warning about unknown props on a DOM element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已经修改了,使用DEFAULT_OMIT_PROPS 排除了

}

const DEFAULT_OMIT_PROPS = [
Expand All @@ -65,6 +67,7 @@ const DEFAULT_OMIT_PROPS = [
'activeValue',
'onSelectorRemove',
'focused',
'inputProps',
] as const;

export default React.forwardRef<SelectInputRef, SelectInputProps>(function SelectInput(
Expand Down
20 changes: 20 additions & 0 deletions tests/BaseSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,24 @@ describe('BaseSelect', () => {
expect(container.querySelector('.custom-root-element')).toBeTruthy();
expect(container.querySelector('.rc-select')).toBeFalsy();
});

it('should pass inputProps to internal input', () => {
const { container } = render(
<BaseSelect
prefixCls="rc-select"
showSearch
inputProps={{ spellCheck: false }}
OptionList={OptionList}
displayValues={[]}
emptyOptions
id="test"
onDisplayValuesChange={() => {}}
onSearch={() => {}}
searchValue=""
/>,
);

const input = container.querySelector('input');
expect(input?.getAttribute('spellcheck')).toBe('false');
});
});
Loading