GithubHelp home page GithubHelp logo

barispalabiyik / rci Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leonardodino/rci

0.0 1.0 0.0 159 KB

🔢 better code inputs for the web

Home Page: https://codesandbox.io/s/rci-codeinput-812up?file=/src/Example.tsx

License: MIT License

TypeScript 86.99% CSS 11.40% HTML 1.61%

rci's Introduction

rci "react code input"

better segmented code inputs for the web. primary goals:

  • improved accessibility
  • operating system integration
  • consistent, cross-platform, experience

Compared

img-single-input img-multi-input img-rci
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)
  • autocomplete magic:sparkles:
  • improved accessibility (<label>, tabIndex, minLength/maxLength, etc)

Demo

https://codesandbox.io/s/rci-codeinput-812up?file=/src/Example.tsx

Packages

This repository hosts a few npm packages, the most relevant ones being:

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 you can pass a top-level className directly to CodeInput, all DOM elements rendered by CodeInput contain a data-code-input attribute that can be used to target them individually.

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.

rci's People

Contributors

leonardodino avatar vitordino avatar

Watchers

 avatar

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.