GithubHelp home page GithubHelp logo

react-component / input Goto Github PK

View Code? Open in Web Editor NEW
33.0 6.0 32.0 2.97 MB

React Input Component

License: MIT License

JavaScript 0.87% TypeScript 98.18% Less 0.82% Shell 0.13%
antd ant-design react-component

input's Introduction

rc-input ⌨️

NPM version npm download dumi build status Codecov Dependencies DevDependencies bundle size

Install

rc-input

Usage

import Input from 'rc-input';
import { render } from 'react-dom';

render(<Input placeholder="input" allowClear />, mountNode);

API

Property Type Default Description
prefixCls string rc-input
className string '' additional class name of input
style React.CSSProperties style properties of input
affixWrapperClassName string - className with 'rc-input-affix-wrapper'
groupClassName string - className with 'rc-input-group-wrapper'
wrapperClassName string - className with 'rc-input-wrapper'
addonAfter ReactNode - The label text displayed after (on the right side of) the input field
addonBefore ReactNode - The label text displayed before (on the left side of) the input field
allowClear boolean | { clearIcon: ReactNode } false If allow to remove input content with clear icon
bordered boolean true Whether has border style
defaultValue string - The initial input content
disabled boolean false Whether the input is disabled
id string - The ID for input
maxLength number - The max length
showCount boolean | { formatter: ({ value: string, count: number, maxLength?: number }) => ReactNode } false Whether show text count
prefix ReactNode - The prefix icon for the Input
suffix ReactNode - The suffix icon for the Input
type string text The type of input, see: MDN( use Input.TextArea instead of type="textarea")
value string - The input content value
onChange function(e) - Callback when user input
onPressEnter function(e) - The callback function that is triggered when Enter key is pressed

inputRef

const inputRef = useRef(null);

useEffect(() => {
  inputRef.current.focus();// the input will get focus
  inputRef.current.blur();// the input will lose focus
  console.log(inputRef.current.input);// The origin input element
}, []);
// ....
<Input ref={inputRef} />
Property Type Description
focus (options?: InputFocusOptions) => void The input get focus when called
blur () => void The input loses focus when called
input HTMLInputElement | null The origin input element

Development

npm install
npm start

License

rc-input is released under the MIT license.

input's People

Contributors

afc163 avatar food-billboard avatar jarvisart avatar kiner-tang avatar lgtm-com[bot] avatar madccc avatar puchunjie avatar yoyo837 avatar yyz945947732 avatar zombiej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

input's Issues

Click clear icon will set value to empty string

  const handleReset = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
    setValue('');
    focus();
    if (inputRef.current) {
      resolveOnChange(inputRef.current, e, onChange);
    }
  };

Empty string is diffrent between undefined when it's sent to server.

Clear button is not accessible

Hello, we discovered that clear button which appears when allowClear property used is not accessible due to 2 reasons:

  • button wrapper uses tabindex=-1 which makes it inaccessible through the keyboard using tab/shift+tab
  • button wrapper uses span tag which prevent to click it via space or shift when it is on focus

I opened PR to fix this and added tests to check behavior, could you check it please

#63

Add support for displaying remaining character count in rc-input

Currently, the rc-input package only provides support for displaying the character count of the provided input. It would be helpful to have the ability to switch to display the remaining character count also. This would be especially useful for situations where a user is limited to a specific number of characters, such as in form inputs or text areas.

I am requesting that support for displaying the remaining character count be added to the rc-input package. This would be a valuable addition to the package.

Thank you for considering this feature request.

selectionStart / selectionEnd are always 0

After this change (most likely) #54, which came into effect with antd 5.12.3, onchange event from the input always has selectionStart / selectionEnd properties set to 0 instead of the actual numbers

We have custom input processing (related to the currency formatting), which worked perfectly for the past 6 years until this change.

Would it be possible to have a look into this issue?

Failed to set the 'selectionStart' property on 'HTMLInputElement': The input element's type ('email') does not support selection.

Recent change v1.4.3...v1.4.4#diff-94b5cf5856a42bc2e70f9e2b690fda2b65151186e6b007466ff6c6744c40e2c8R30

currentTarget.selectionStart = target.selectionStart; currentTarget.selectionEnd = target.selectionEnd;

breaks input type email functionality. With error:

Failed to set the 'selectionStart' property on 'HTMLInputElement': The input element's type ('email') does not support selection.

在 Mac 系统上使用中文输入法时,onPressEnter 是否存在问题?

公司项目使用了 Antd,而 Antd 依赖了 rc-input 的代码。通过查看源码后发现 onPressEnter 使用了 onkeydown 实现检查是否按下 Enter,但这种实现会导致在 Mac 系统上使用中文输入法的情况下,输入任意内容不选择任何联想项时按下 Enter 键,会触发对应逻辑,正常情况下应该不做处理?个人尝试后发现使用 onkeypress 是没有问题的。

这是我写的 最小复现 Demo,如果使用非 onkeypress 的方式捕获,则会触发此问题,Windows 貌似没有出现此问题。

rc-input 的最小复现

123123.mp4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.