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

Text input example drops keys #287

Closed
joshalbrecht opened this issue Jan 23, 2023 · 12 comments
Closed

Text input example drops keys #287

joshalbrecht opened this issue Jan 23, 2023 · 12 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@joshalbrecht
Copy link

If you type quickly in the Text Input example on the API Reference page, you can see that it drops some characters. This makes it almost completely unusable in practice.

@claytonaalves
Copy link

Yes, I can confirm that. I've got the same behavior here.

Works ok if you type slowly thou.

@falkoschindler falkoschindler self-assigned this Jan 26, 2023
@falkoschindler falkoschindler added the bug Something isn't working label Jan 26, 2023
@rodja rodja added this to the v1.1.4 milestone Jan 26, 2023
@falkoschindler
Copy link
Contributor

falkoschindler commented Jan 26, 2023

You are right, typing in a text input can drop keys.

It actually happens because every value change is sent to the server where the event is processed and the new value is sent back to the client. I implemented this roundtrip because Quasar's QToggle simply wouldn't change its state when clicking on it even though the event was sent to the server. Somehow I had to send the updated value back to the client for it to move.

While this technique might be needed for some elements for whatever reason, it might not be necessary for others. Apparently we don't need to send the new value for a QInput. So I'll introduce an option in NiceGUI's ValueElement base class so that ui.toggle can behave differently than ui.input in this regard. This will hopefully avoid dropping keys while typing.

@falkoschindler
Copy link
Contributor

I checked the behavior for all elements deriving from ValueElement with the following code:

with ui.row():
    ui.checkbox('Checkbox')
    ui.switch('Switch')
with ui.row():
    ui.radio(['A', 'B', 'C'])
    ui.select(['A', 'B', 'C'])
    ui.toggle(['A', 'B', 'C'])
with ui.row():
    ui.input('Input')
    ui.number('Number')
    ui.color_input('Color input')
with ui.row():
    with ui.menu() as menu:
        ui.menu_item('Ok')
    ui.button('Menu', on_click=menu.open)
    with ui.dialog() as dialog:
        ui.button('Ok', on_click=dialog.close)
    ui.button('Dialog', on_click=dialog.open)
with ui.row().classes('w-96'):
    lp = ui.linear_progress()
    cp = ui.circular_progress()
    ui.slider(min=0, max=1, step=0.1).bind_value_to(lp, 'value').bind_value_to(cp, 'value')
with ui.row():
    ui.date()
    ui.time()

I tried it once with sending changed values back to the client and once without.
To detect problems caused by the roundtrip, I simulated a slow connection using the Chrome developer tools.

  • All input elements involving typing (ui.input, ui.number, and ui.color_input) show flickering and lost characters. When disabling the roundtrip, the flickering is gone but they get cleared when loosing focus. So we probably need to set their state sometime, maybe on change but with some throttling.
  • The minute finger of the ui.time element flickers when being dragged around quickly. In contrast to the three aforementioned input elements, it isn't cleared after loosing focus.
  • All other elements don't show any flickering or lost values. However, they don't work at all if changed values are not sent back to them.

So I guess we should treat ui.input, ui.number, ui.color_input, and ui.time differently then the other value elements by updating the frontend later or less frequently. But I'm not sure about the details.

@falkoschindler
Copy link
Contributor

Updating on blur doesn't work well. When throttling the network connection, delayed messages from the server are messing up the user experience.

FI-Mihej added a commit to FI-Mihej/nicegui that referenced this issue Jan 27, 2023
@FI-Mihej
Copy link
Contributor

Hello! I've made a fix for this issue. Please review: #306

@rodja rodja modified the milestones: v1.1.4, v1.1.5 Jan 28, 2023
FI-Mihej added a commit to FI-Mihej/nicegui that referenced this issue Jan 28, 2023
@falkoschindler
Copy link
Contributor

falkoschindler commented Jan 28, 2023

Based on @FI-Mihej's PR (see discussion over at #306) I came up with a solution that might be the essence of #306 without introducing too much change of behavior and/or API: https://github.com/zauberzeug/nicegui/tree/no_loopback_for_input

The key changes are as follows:

  • Value elements have a static parameter LOOPBACK set to True by default.
  • ui.input, ui.number, and ui.color_input overwrite LOOPBACK with False.
  • On a value change event the server won't send an update message if loopback is false.
  • On a update:model-value event the client will set the model-value directly if loopback is false.

The last point was the missing piece: The client needs to listen to the change event and set the value directly. Otherwise the element would need to wait for a server response.

What do you think?

@kepler
Copy link

kepler commented Jan 31, 2023

This issue is also biting us quite hard: when using ui.input with props=textarea, the caret jumps to the end of the box when typing mildly fast. So any quick fix is very welcome.

@rodja
Copy link
Member

rodja commented Jan 31, 2023

Hopefully we will merge #306 today. v1.1.5 will be released tomorrow at the latest.

falkoschindler added a commit to FI-Mihej/nicegui that referenced this issue Feb 1, 2023
…auberzeug#287-Text-input-example-drops-keys"

This reverts commit f347b37, reversing
changes made to 0fb1051.
falkoschindler added a commit to FI-Mihej/nicegui that referenced this issue Feb 1, 2023
falkoschindler added a commit to FI-Mihej/nicegui that referenced this issue Feb 1, 2023
falkoschindler added a commit that referenced this issue Feb 1, 2023
@rodja
Copy link
Member

rodja commented Feb 1, 2023

Some last minute tests before the release uncovered major drawbacks with the new implementation. We hope to find a solution as soon as possible. Sorry for the delay.

@falkoschindler
Copy link
Contributor

I pushed a possible fix to https://github.com/zauberzeug/nicegui/tree/loopback.
Needs review and thorough testing.

rodja added a commit that referenced this issue Feb 2, 2023
rodja added a commit that referenced this issue Feb 2, 2023
@falkoschindler
Copy link
Contributor

The fix from 061b388 is working nicely.

@rodja
Copy link
Member

rodja commented Feb 2, 2023

v1.1.5 has just been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants