Skip to content

Commit

Permalink
Fix for #148: open links in new tab (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
cswamy committed Feb 7, 2024
1 parent cec25c6 commit 13a1d46
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions demo/components_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class Delivery(BaseModel):
components=[c.Text(text='Pydantic (External link)')],
on_click=GoToEvent(url='https://pydantic.dev'),
),
c.Link(
components=[c.Text(text='FastUI repo (New tab)')],
on_click=GoToEvent(url='https://github.com/pydantic/FastUI', target='_blank'),
),
],
),
],
Expand Down
6 changes: 5 additions & 1 deletion src/npm-fastui/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export function useFireEvent(): { fireEvent: (event?: AnyEvent) => void } {
}
case 'go-to':
if (event.url) {
location.goto(event.url)
if (event.target) {
window.open(event.url, event.target)
} else {
location.goto(event.url)
}
}
if (event.query) {
location.setQuery(event.query)
Expand Down
1 change: 1 addition & 0 deletions src/npm-fastui/src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface GoToEvent {
query?: {
[k: string]: string | number
}
target?: '_blank'
type: 'go-to'
}
export interface BackEvent {
Expand Down
1 change: 1 addition & 0 deletions src/python-fastui/fastui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GoToEvent(BaseModel):
# can be a path or a full URL
url: Union[str, None] = None
query: Union[Dict[str, Union[str, float, None]], None] = None
target: Union[Literal['_blank'], None] = None
type: Literal['go-to'] = 'go-to'


Expand Down

0 comments on commit 13a1d46

Please sign in to comment.