Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions nicegui/elements/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self,
value: str = '',
password: bool = False,
password_toggle_button: bool = False,
prefix: Optional[str] = None,
suffix: Optional[str] = None,
on_change: Optional[Handler[ValueChangeEventArguments]] = None,
autocomplete: Optional[list[str]] = None,
validation: Optional[Union[ValidationFunction, ValidationDict]] = None,
Expand Down Expand Up @@ -46,6 +48,8 @@ def __init__(self,
:param value: the current value of the text input
:param password: whether to hide the input (default: False)
:param password_toggle_button: whether to show a button to toggle the password visibility (default: False)
:param prefix: a prefix to prepend to the displayed value
:param suffix: a suffix to append to the displayed value
:param on_change: callback to execute when the value changes
:param autocomplete: optional list of strings for autocompletion
:param validation: dictionary of validation rules or a callable that returns an optional error message (default: None for no validation)
Expand All @@ -66,9 +70,30 @@ def toggle_type(_):

self._props['_autocomplete'] = autocomplete or []

if prefix is not None:
self._props['prefix'] = prefix
if suffix is not None:
self._props['suffix'] = suffix
Comment on lines +73 to +76
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new prefix and suffix parameters for ui.input lack test coverage. Consider adding tests that verify:

  1. Elements can be created with prefix/suffix parameters
  2. The set_prefix and set_suffix methods work correctly
  3. Dynamic updates to prefix/suffix are reflected in the UI

Given that other similar parameters in test_input.py have comprehensive test coverage, this feature should have tests as well.

Copilot uses AI. Check for mistakes.

def set_autocomplete(self, autocomplete: Optional[list[str]]) -> None:
"""Set the autocomplete list."""
self._props['_autocomplete'] = autocomplete

def set_prefix(self, text: Optional[str]) -> None:
"""
Set the prefix.

:param text: the context of the prefix.
"""
self._props['prefix'] = text

def set_suffix(self, text: Optional[str]) -> None:
"""
set the suffix.

:param text: the context of the suffix.
"""
self._props['suffix'] = text

def _handle_value_change(self, value: Any) -> None:
super()._handle_value_change(value)
Expand Down
16 changes: 16 additions & 0 deletions nicegui/elements/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ def sanitize(self) -> None:
value = float(round(value, self.precision))
self.value = float(self.format % value) if self.format else value
self.update()

def set_prefix(self, text: Optional[str]) -> None:
"""
Set the prefix.
:param text: the context of the prefix.
"""
self._props['prefix'] = text

def set_suffix(self, text: Optional[str]) -> None:
"""
set the suffix.
:param text: the context of the suffix.
"""
self._props['suffix'] = text
Comment on lines 119 to 133
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new set_prefix and set_suffix methods for ui.number lack test coverage. Consider adding tests that verify these methods work correctly and dynamically update the UI. Note that while the prefix and suffix constructor parameters already existed, the new setter methods are untested.

Given that other similar parameters in test_number.py have comprehensive test coverage, these new methods should have tests as well.

Copilot uses AI. Check for mistakes.

def _event_args_to_value(self, e: GenericEventArguments) -> Any:
if not e.args:
Expand Down
Loading