Skip to content

Feature/chips enter value on blur - #1

Closed
bakspace-itk wants to merge 8 commits into
mainfrom
feature/chips_enter_value_on_blur
Closed

Feature/chips enter value on blur#1
bakspace-itk wants to merge 8 commits into
mainfrom
feature/chips_enter_value_on_blur

Conversation

@bakspace-itk

@bakspace-itk bakspace-itk commented Jan 28, 2026

Copy link
Copy Markdown
Owner

Motivation

Implementation

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
  • If this PR addresses a security issue, it has been coordinated via the security advisory process.
  • Pytests have been added (or are not necessary).
  • Documentation has been added (or is not necessary).

This change adds a blur event handler to the input_chips component that automatically commits the current input value as a new chip when the input field loses focus. This provides a better user experience by allowing users to add chips without explicitly pressing Enter.

The implementation:
- Uses the existing addValue() method to respect the new-value-mode setting
- Only adds non-empty values (trimmed)
- Clears the input field after adding the value

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
…s loss

This change adds blur event handling to the input_chips component using Python event listeners instead of JavaScript. When the input field loses focus, any typed value is automatically added as a chip.

Implementation details:
- Added _handle_input_value_change() to track what user is typing
- Added _handle_blur() to process the value when field loses focus
- Respects new-value-mode setting (add, add-unique, toggle)
- Added comprehensive tests for blur functionality with all modes

The solution works by:
1. Listening to 'input-value' events to track current input
2. Listening to 'blur' events to trigger chip creation
3. Applying the appropriate new-value-mode logic (add/add-unique/toggle)
4. Updating the component value which triggers UI update

Tests:
- All existing tests pass
- New test_input_chips_blur_adds_value() validates blur behavior for all modes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
The previous test didn't properly test the different new-value-mode behaviors.
Now it mirrors the test_add_new_values test by:
- Adding 'x' once
- Adding 'y' twice
- Validating that toggle mode removes the second 'y' (leaving only 'x')
- Validating that add-unique mode keeps only one 'y'
- Validating that add mode keeps both 'y' values

This ensures blur behavior matches Enter key behavior for all modes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
Documentation improvements:
- Clarified docstring to explain blur behavior (Tab, click away)
- Added explicit new_value_mode behavior descriptions with examples
- Explained chip removal via "x" icon

Code improvements:
- Added explanatory comments in test showing expected behavior for each mode
- Fixed linting warnings (use unpacking instead of concatenation)

All tests pass, linting clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
The _handle_blur method doesn't use the event parameter - it only uses
the tracked _current_input_value. Removing the parameter follows the
NiceGUI pattern where handlers without event data don't take parameters.

Pylint now rates the file 10.00/10.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
Added a comprehensive example showing how input_chips automatically adds
values when the field loses focus (Tab, click away) in addition to Enter key.

The example demonstrates all three new_value_mode options:
- toggle: Adds if absent, removes if present
- add: Always adds (allows duplicates)
- add-unique: Only adds if not already present

This provides users with a clear reference for the blur feature.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Kristian Bak <kriba@aarhus.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant