Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { HolderRef } from '@rc-component/input/lib/BaseInput';
import { BaseInputProps } from '@rc-component/input/lib/interface';
import { InputFocusOptions, triggerFocus } from '@rc-component/input/lib/utils/commonUtils';
import useFrame from './hooks/useFrame';
import useMobile from '@rc-component/util/lib/hooks/useMobile';

export type { ValueType };

Expand Down Expand Up @@ -133,7 +134,7 @@ const InternalInputNumber = React.forwardRef(
downHandler,
keyboard,
changeOnWheel = false,
controls = true,
controls,

stringMode,

Expand Down Expand Up @@ -176,6 +177,9 @@ const InternalInputNumber = React.forwardRef(
}
}

const isMobile = useMobile();
Copy link
Member

Choose a reason for hiding this comment

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

都去掉吧,v6 就开发给人用。antd 里 css 藏起来

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯, antd v6 不需要做任何操作了

const mergedControls = controls ?? !isMobile;

// ====================== Parser & Formatter ======================
/**
* `precision` is used for formatter & onChange.
Expand Down Expand Up @@ -607,7 +611,7 @@ const InternalInputNumber = React.forwardRef(
onCompositionEnd={onCompositionEnd}
onBeforeInput={onBeforeInput}
>
{controls && (
{mergedControls && (
<StepHandler
prefixCls={prefixCls}
upNode={upHandler}
Expand Down
6 changes: 0 additions & 6 deletions src/StepHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable react/no-unknown-property */
import * as React from 'react';
import cls from 'classnames';
import useMobile from '@rc-component/util/lib/hooks/useMobile';
import raf from '@rc-component/util/lib/raf';
import SemanticContext from './SemanticContext';

Expand Down Expand Up @@ -71,11 +70,6 @@ export default function StepHandler({
);

// ======================= Render =======================
const isMobile = useMobile();
if (isMobile) {
return null;
}

const handlerClassName = `${prefixCls}-handler`;

const upClassName = cls(handlerClassName, `${handlerClassName}-up`, {
Expand Down
14 changes: 9 additions & 5 deletions tests/mobile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { render } from './util/wrapper';
import InputNumber from '../src';
import { renderToString } from 'react-dom/server';
import InputNumber from '../src';
import { render } from './util/wrapper';

jest.mock('@rc-component/util/lib/isMobile', () => () => true);

Expand All @@ -10,12 +9,17 @@ jest.mock('@rc-component/util/lib/isMobile', () => () => true);

describe('InputNumber.Mobile', () => {
it('not show steps when mobile', () => {
const {container} = render(<InputNumber />);
const { container } = render(<InputNumber />);
expect(container.querySelector('.rc-input-number-handler-wrap')).toBeFalsy();
});

it('should render in server side', () => {
const serverHTML = renderToString(<InputNumber />);
expect(serverHTML).toContain('rc-input-number-handler-wrap');
})
});

it('can show steps when set controls to true', () => {
const { container } = render(<InputNumber controls />);
expect(container.querySelector('.rc-input-number-handler-wrap')).toBeTruthy();
});
});