Skip to content

Conversation

@Yuerchu
Copy link
Contributor

@Yuerchu Yuerchu commented Dec 3, 2025

This pull request adds support for prefix and suffix text to both the Input and Number elements in the NiceGUI library. These enhancements allow developers to easily display additional context before or after the input value, such as units or currency symbols. The changes include new constructor parameters, updates to property handling, and new setter methods.

Input element enhancements

  • Added prefix and suffix parameters to the Input element constructor, allowing developers to specify text to display before or after the input value. [1] [2]
  • Updated internal property handling in Input to store the prefix and suffix values if provided.
  • Introduced set_prefix and set_suffix methods to dynamically update prefix and suffix text for the Input element.

Number element enhancements

  • Added set_prefix and set_suffix methods to the Number element, enabling dynamic updates of prefix and suffix text.
461115c3d32150f95f9416cec0d013dd ad90a76b0bb2f84fbda9fa77c9ca80f0

Copilot AI review requested due to automatic review settings December 3, 2025 07:56
Copilot finished reviewing on behalf of Yuerchu December 3, 2025 07:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances both ui.input and ui.number elements by adding support for prefix and suffix text display, allowing developers to show contextual information like currency symbols or units alongside input values.

Key Changes

  • Added prefix and suffix constructor parameters to ui.input element for displaying text before/after input values
  • Introduced set_prefix() and set_suffix() setter methods for both ui.input and ui.number elements to enable dynamic updates
  • Updated parameter documentation for both elements

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
nicegui/elements/input.py Added prefix/suffix constructor parameters and corresponding setter methods to the Input element
nicegui/elements/number.py Added set_prefix() and set_suffix() methods to enable dynamic prefix/suffix updates for the Number element

Comment on lines +73 to +76
if prefix is not None:
self._props['prefix'] = prefix
if suffix is not None:
self._props['suffix'] = suffix
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.
Comment on lines 119 to 133
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
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.
@evnchn
Copy link
Collaborator

evnchn commented Dec 3, 2025

Hello @Yuerchu thanks for the PR. Other than the comments by GitHub copilot I don't have much to add for now.

But should we make it bindable as well?

@falkoschindler
Copy link
Contributor

@evnchn I'm not so sure about binding methods. They add a lot of repetitive code and I don't really see the application for binding prefixes and suffixes. We can always add them later if needed.

@falkoschindler falkoschindler added the feature Type/scope: New feature or enhancement label Dec 3, 2025
@falkoschindler falkoschindler added this to the 3.5 milestone Dec 3, 2025
@falkoschindler falkoschindler added the in progress Status: Someone is working on it label Dec 3, 2025
@Yuerchu
Copy link
Contributor Author

Yuerchu commented Dec 4, 2025

I've tried to fix some of the syntax issues pointed out by Copilot. But I don't have enough time in the short term to write unit tests.

@evnchn
Copy link
Collaborator

evnchn commented Dec 4, 2025

@Yuerchu I don't have permission to push for some reason, but here is the test code:

def test_input_with_prefix_suffix(screen: Screen):
    @ui.page('/')
    def page():
        n = ui.input(prefix='MyPrefix', suffix='MySuffix')

        def change_prefix_suffix():
            n.set_prefix('NewPrefix')
            n.set_suffix('NewSuffix')

        ui.button('Change', on_click=change_prefix_suffix)

    screen.open('/')
    screen.should_contain('MyPrefix')
    screen.should_contain('MySuffix')
    screen.click('Change')
    screen.should_contain('NewPrefix')
    screen.should_contain('NewSuffix')

Same for ui.number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Type/scope: New feature or enhancement in progress Status: Someone is working on it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants