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

feat: support custom quick-jumper input #595

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions src/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SelectProps } from 'rc-select';
import type { OptionProps } from 'rc-select/es/Option';
import KEYCODE from 'rc-util/lib/KeyCode';
import React from 'react';
import type { PaginationLocale } from './interface';
import type { PaginationLocale, PaginationData } from './interface';

interface InternalSelectProps extends SelectProps {
/**
Expand All @@ -11,7 +11,7 @@ interface InternalSelectProps extends SelectProps {
popupMatchSelectWidth?: boolean;
}

interface OptionsProps {
interface OptionsProps extends Pick<PaginationData, 'inputComponentClass'> {
disabled?: boolean;
locale: PaginationLocale;
rootPrefixCls: string;
Expand Down Expand Up @@ -39,8 +39,9 @@ const Options: React.FC<OptionsProps> = (props) => {
quickGo,
rootPrefixCls,
selectComponentClass: Select,
inputComponentClass: Input = 'input',
selectPrefixCls,
disabled,
disabled = false,
buildOptionText,
} = props;

Expand Down Expand Up @@ -166,7 +167,7 @@ const Options: React.FC<OptionsProps> = (props) => {
goInput = (
<div className={`${prefixCls}-quick-jumper`}>
{locale.jump_to}
<input
<Input
disabled={disabled}
type="text"
value={goInputText}
Expand Down
2 changes: 2 additions & 0 deletions src/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
selectPrefixCls = 'rc-select',
className,
selectComponentClass,
inputComponentClass,

// control
current: currentProp,
Expand Down Expand Up @@ -585,6 +586,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
rootPrefixCls={prefixCls}
disabled={disabled}
selectComponentClass={selectComponentClass}
inputComponentClass={inputComponentClass}
Copy link
Member

Choose a reason for hiding this comment

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

开 components 属性吧,类似 DatePicker。

selectComponentClass 不是好的 API,可以趁这个机会废弃掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

哈哈哈 搞这出,现在一个整个文件太多行了,我看看能不能一起拆掉吧

selectPrefixCls={selectPrefixCls}
changeSize={showSizeChanger ? changePageSize : null}
pageSize={pageSize}
Expand Down
6 changes: 5 additions & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ export interface PaginationData {
showPrevNextJumpers: boolean;
showQuickJumper: boolean | object;
showTitle: boolean;
simple: boolean | { readOnly?: boolean; };
simple: boolean | { readOnly?: boolean };
disabled: boolean;

locale: PaginationLocale;

style: React.CSSProperties;

selectComponentClass: React.ComponentType;
/**
* @since 4.3.0
*/
inputComponentClass?: React.ComponentType<React.InputHTMLAttributes<any>>;
prevIcon: React.ComponentType | React.ReactNode;
nextIcon: React.ComponentType | React.ReactNode;
jumpPrevIcon: React.ComponentType | React.ReactNode;
Expand Down
50 changes: 50 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,56 @@ describe('Other props', () => {
container.querySelector('.rc-pagination-options-quick-jumper-button'),
).toBeDisabled();
});

it('should support inputComponentClass', () => {
const Input = jest.fn((props) => (
<input {...props} data-testid="custom-input" />
));
const { getByTestId } = render(
<Pagination
showQuickJumper
inputComponentClass={Input}
defaultPageSize={20}
defaultCurrent={5}
total={450}
/>,
);
const inputDom = getByTestId('custom-input');
expect(inputDom).toBeTruthy();

// expect params
expect(Input).toHaveBeenLastCalledWith(
expect.objectContaining({
'aria-label': expect.any(String),
disabled: expect.anything(),
onBlur: expect.any(Function),
onChange: expect.any(Function),
onKeyUp: expect.any(Function),
type: 'text',
value: expect.any(String),
}),
expect.anything(),
);

// input change value
fireEvent.change(inputDom, { target: { value: '2' } });
expect(inputDom).toHaveValue('2');
expect(Input).toHaveBeenLastCalledWith(
expect.objectContaining({
value: '2',
}),
expect.anything(),
);

// input blur
fireEvent.blur(inputDom);
expect(Input).toHaveBeenLastCalledWith(
expect.objectContaining({
value: '',
}),
expect.anything(),
);
});
});

// https://github.com/ant-design/ant-design/issues/10524
Expand Down
Loading