tui: fix focus management and dialog interactions

This commit is contained in:
Dax Raad
2025-11-02 19:07:22 -05:00
parent f68374ad22
commit f42e1c6375
7 changed files with 12 additions and 44 deletions

View File

@@ -130,7 +130,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
if (evt.name === "return") {
const option = selected()
if (option) {
evt.preventDefault()
// evt.preventDefault()
if (option.onSelect) option.onSelect(dialog)
props.onSelect?.(option)
}

View File

@@ -1,17 +1,8 @@
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
import {
batch,
createContext,
createEffect,
Show,
useContext,
type JSX,
type ParentProps,
} from "solid-js"
import { batch, createContext, Show, useContext, type JSX, type ParentProps } from "solid-js"
import { useTheme } from "@tui/context/theme"
import { Renderable, RGBA } from "@opentui/core"
import { createStore } from "solid-js/store"
import { createEventBus } from "@solid-primitives/event-bus"
export function Dialog(
props: ParentProps<{
@@ -59,7 +50,6 @@ function init() {
}[],
size: "medium" as "medium" | "large",
})
const allClosedEvent = createEventBus<void>()
useKeyboard((evt) => {
if (evt.name === "escape" && store.stack.length > 0) {
@@ -90,12 +80,6 @@ function init() {
}, 1)
}
createEffect(() => {
if (store.stack.length === 0) {
allClosedEvent.emit()
}
})
return {
clear() {
for (const item of store.stack) {
@@ -108,7 +92,9 @@ function init() {
refocus()
},
replace(input: any, onClose?: () => void) {
if (store.stack.length === 0) focus = renderer.currentFocusedRenderable
if (store.stack.length === 0) {
focus = renderer.currentFocusedRenderable
}
for (const item of store.stack) {
if (item.onClose) item.onClose()
}
@@ -129,9 +115,6 @@ function init() {
setSize(size: "medium" | "large") {
setStore("size", size)
},
get allClosedEvent() {
return allClosedEvent
},
}
}