charmbracelet / bubbles

TUI components for Bubble Tea 🫧
MIT License
5.35k stars 252 forks source link

feat: Add NumberInput in bubbles #481

Open anirudhaCodes opened 7 months ago

anirudhaCodes commented 7 months ago

Is your feature request related to a problem? Please describe. Currently, Bubbles lacks a component for numeric input fields. Users may require this functionality for various use cases, such as collecting numerical data (Number only) or setting numeric parameters.

Describe the solution you'd like

I would like to propose adding a NumberInput component to our library. This component would provide users with a text input field specifically designed for entering numeric values. It should support pasting functionality. Additionally, it should offer customization options for styling and behavior to suit different application needs.

Describe alternatives you've considered

One alternative could be using a standard text input field and validating the input on the client-side to ensure it only accepts numeric values. However, this approach may not provide the user with a consistent experience and could require additional effort for input validation and error handling.

[Assign this to Me.] [should we add this feat in textInput or should we create numberInput]

meowgorithm commented 7 months ago

Hi! So actually textinput contains a Validate property which can be used to restrict input to numbers only. The credit card example illustrates how to do this.

anirudhaCodes commented 7 months ago

@meowgorithm Thank you for the reply. In the Bubbles library, are various input types like number, email, password (hiding text), URL, etc., intended to be implemented using the Validate property of textInput, or are there plans to introduce specific components or features for these input types in the future?

meowgorithm commented 7 months ago

So most of these can be done with textinput and the plan is to remain that way for maintainability unless there are good reasons to introduce new inputs. You raise a good point about documentation however.

For password input you can set EchoMode on textinput.Model to EchoPassword:

import "github.com/charmbracelet/bubbles/textinput"

passwordInput := textinput.New()
passwordInput.EchoMode = textinput.EchoPassword
anirudhaCodes commented 7 months ago

Understood. I was just trying to contribute to the codebase. As I'm interested in contributing to the Bubbles library (or any other Charm library), I'm curious about the roadmap for future components or features. Are there any plans or discussions regarding upcoming components or enhancements that could use contributions from the community? It would be helpful to know if there are any specific areas where contributions would be particularly valuable.