Skip to content

Commit 13a1d46

Browse files
authored
Fix for #148: open links in new tab (#157)
1 parent cec25c6 commit 13a1d46

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

demo/components_list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class Delivery(BaseModel):
7878
components=[c.Text(text='Pydantic (External link)')],
7979
on_click=GoToEvent(url='https://pydantic.dev'),
8080
),
81+
c.Link(
82+
components=[c.Text(text='FastUI repo (New tab)')],
83+
on_click=GoToEvent(url='https://github.com/pydantic/FastUI', target='_blank'),
84+
),
8185
],
8286
),
8387
],

src/npm-fastui/src/events.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export function useFireEvent(): { fireEvent: (event?: AnyEvent) => void } {
3535
}
3636
case 'go-to':
3737
if (event.url) {
38-
location.goto(event.url)
38+
if (event.target) {
39+
window.open(event.url, event.target)
40+
} else {
41+
location.goto(event.url)
42+
}
3943
}
4044
if (event.query) {
4145
location.setQuery(event.query)

src/npm-fastui/src/models.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export interface GoToEvent {
141141
query?: {
142142
[k: string]: string | number
143143
}
144+
target?: '_blank'
144145
type: 'go-to'
145146
}
146147
export interface BackEvent {

src/python-fastui/fastui/events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class GoToEvent(BaseModel):
1818
# can be a path or a full URL
1919
url: Union[str, None] = None
2020
query: Union[Dict[str, Union[str, float, None]], None] = None
21+
target: Union[Literal['_blank'], None] = None
2122
type: Literal['go-to'] = 'go-to'
2223

2324

0 commit comments

Comments
 (0)