Skip to content

Commit

Permalink
support kebab-case event types
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 14, 2023
1 parent d3b9048 commit 78d679c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nicegui/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from typing_extensions import Self

from . import context, core, events, json, outbox, storage
from . import context, core, events, helpers, json, outbox, storage
from .awaitable_response import AwaitableResponse, NullResponse
from .dependencies import Component, Library, register_library, register_vue_component
from .elements.mixins.visibility import Visibility
Expand Down Expand Up @@ -388,7 +388,7 @@ def on(self,
if handler:
listener = EventListener(
element_id=self.id,
type=type,
type=helpers.kebab_to_camel_case(type),
args=[args] if args and isinstance(args[0], str) else args, # type: ignore
handler=handler,
throttle=throttle,
Expand Down
5 changes: 5 additions & 0 deletions nicegui/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ def in_thread(host: str, port: int) -> None:
thread = threading.Thread(target=in_thread, args=(host, port), daemon=True)
thread.start()
return thread, cancel


def kebab_to_camel_case(string: str) -> str:
"""Convert a kebab-case string to camelCase."""
return ''.join(word.capitalize() if i else word for i, word in enumerate(string.split('-')))

0 comments on commit 78d679c

Please sign in to comment.