Skip to content

Commit

Permalink
fix and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystalWindSnake committed Nov 23, 2024
1 parent 1422b5c commit ef0b0b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions __tests/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,30 @@ def _():

drap_move("max", page, offset_x=-100)
label.expect_equal_text("{'min': 0, 'max': 92}")


def test_ref_value_change(browser: BrowserManager, page_path: str):
r_value = to_ref(
{
"min": 0,
"max": 100,
}
)

@ui.page(page_path)
def _():
rxui.range(min=0, max=100, value=r_value).classes("target").props(
"label-always"
)

ui.button(
"change value", on_click=lambda: r_value.set_value({"min": 10, "max": 90})
).classes("change-btn")

page = browser.open(page_path)
button = page.Button(".change-btn")

button.click()

page.should_contain("10")
page.should_contain("90")
13 changes: 13 additions & 0 deletions ex4nicegui/reactive/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ex4nicegui.utils.types import _TMaybeRef as TMaybeRef
from nicegui import Tailwind, ui
from nicegui.elements.mixins.text_element import TextElement
from nicegui.elements.mixins.value_element import ValueElement
from ex4nicegui.reactive.services.reactive_service import inject_handle_delete
from ex4nicegui.reactive.scopedStyle import ScopedStyle
from ex4nicegui.reactive.mixins.disableable import DisableableMixin
Expand Down Expand Up @@ -223,6 +224,18 @@ def _():
cast(TextElement, self.element).set_text(to_value(value))
self.element.update()

return self

if prop == "value" and isinstance(self.element, ValueElement):

@self._ui_effect
def _():
element = cast(ValueElement, self.element)
element.set_value(to_value(value))
self.element.update()

return self

@self._ui_effect
def _():
element = cast(ui.element, self.element)
Expand Down

0 comments on commit ef0b0b1

Please sign in to comment.