关于
🔢 适用于 React/Web 的更好代码输入组件
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文rci "react code input"
better segmented code inputs for the web. primary goals:
- improved accessibility
- operating system integration
- consistent, cross-platform, experience
Compared
![]() |
![]() |
![]() |
|---|---|---|
| regular input | multi-input | rci |
rci uses a single DOM input element, overlayed on top of plain divs for styling. most other implementations of this pattern are based on multiple inputs.
using multiple inputs gives out-of-the-box style consistency, but comes with the disadvantage of JavaScript hacks to deal with focus shifting and pasting, and accessibility issues.
using a single input (rci approach) allows for:
- native keyboard shortcuts and selection (including selecting multiple segments)
- :sparkles:
autocompletemagic:sparkles: - improved accessibility (
<label>,tabIndex,minLength/maxLength, etc)
Demo
https://rci.netlify.app (code here, uses tailwind)
(for vanilla css, see the codesandbox. a nice starter for CSS Modules usage)
Packages
This repository hosts a few npm packages, the most relevant ones being:
use-code-input: low-level hook handling selection via refrci: opinionated component (CodeInput) built on top ofuse-code-input
most users will be better served by using rci, as the internals of this component won't vary much from app to app.
the hook package is intended for usage only in design system projects which wish to retain absolute control of rendered DOM elements.
Styling
packages in this repo don't bundle any built-in style, besides the base minimum for it to function (zIndex, positioning, etc).
for styling all elements rendered by CodeInput have a dedicated className prop:
classNameinputClassNamescrollWrapperClassNamesegmentWrapperClassName
Bundle size
despite not being part of the primary goals, weight is heavily considered while developing.
| package | size |
|---|---|
rci |
|
use-code-input |
|
use-is-focused |
Caveats
there's currently no support for displaying separators between sequences (example: ___-___).
for simplicity of implementation and to reduce the amount of CSS the user needs to provide, this component assumes a font with fixed advances for the characters accepted. this means using a monospaced or tabular lining font for numeric values. for alphanumeric values the font must be monospaced.
this project is still pending a thorough a11y validation. for cases in which accessibility is paramount, please use a simple native single input.
探索相关项目
加载中…


