Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] input widget: limit width of the widget and the length of the entered text #1281

Open
spflaumer opened this issue Feb 5, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@spflaumer
Copy link

Description of the requested feature

Adding a parameter, :max-length, to the input element that:

  • sets the maximum input length, beyond which no :onchange events will occur (except for backspace, naturally)
  • sets the input elements initial size to fit at most that amount of characters, to avoid creating dead space
    Potentially also adding a parameter, :pattern, to the input element as well, that would match the characters being input to some regex, discarding those that don't match.

Proposed configuration syntax

; ...
(input
    ; ...
    :pattern `[0-9]*`
    :max-length 4)
; ...

Additional context

Hello,
I've been using eww for about a week now, to write a status bar and some extra widgets, and I've really come to enjoy it.
However, once I've gotten to writing a calendar widget, I noticed that it's impossible to set the size of the input widget to something below it's default initial size. I've tried setting:

  • :space-evenly to false on the parent box element
  • :width to 0
  • min-width to 0

The only way, I'm currently aware of, at least, is to set the margin to a negative value, tricking eww into treating it as a smaller thing than it really is.

This is fine and, in my opinion, a perfectly acceptable, albeit a bit hacky, solution. But, when it actually comes to using the input, entering any text beyond the expected limit makes the text then overflow into nearby elements, due to the negative margin. The only way around this, that I can think of, is to put that input element into a literal and have some sort of script or program then restrict the input to a specified amount of characters, n, and, in the case that an attempt is made to enter more than n characters, regenerate the input literal, with it's :value set to the string truncated to n characters.

This, while fairly manageable and easy to do, is a bit tedious, once more than one element should require such treatment, needing to create a new variable for every input element in the widget, beyond adding some overhead from calling an external script or binary, as well as being almost wholly unusable in my use case, since the input element is already within a literal.

Since I assume the default initial size could be also the maximum allowed length of entered characters, adding a :max-length parameter would solve both - specifying a size below the default and limiting input width.

This could be expanded further, adding a :pattern option, that matches the input against a regex expression (just as in HTML).

To that end, thank you for your work on eww; It's a really pleasant to use widget system.

@spflaumer spflaumer added the enhancement New feature or request label Feb 5, 2025
@spflaumer spflaumer changed the title [FEATURE] limit input widget and text length [FEATURE] input widget: limit width of the widget and the length of the entered text Feb 5, 2025
@endic-sam928281
Copy link

Hello, we tried to solve the issue.

This is what we did:

This change adds the :max-length and :pattern parameters to the input widget. The :max-length parameter sets the maximum input length and adjusts the initial size of the input element. The :pattern parameter allows for regex-based input filtering.

You can review changes in this commit: endic-sam928281@2c58b73.

Caution

Disclaimer: The concept of solution was created by AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.


Latta AI seeks to solve problems in open source projects as part of its mission to support developers around the world. Learn more about our mission at https://latta.ai/ourmission . If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants