Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix integrations manager focus
  • Loading branch information
TheodoreSpeaks committed Apr 13, 2026
commit e4c05b8ada596ec08b2d3f7b8dd44cdc068b6e85
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Badge,
Button,
Combobox,
focusFirstTextInputIn,
Input,
Label,
Modal,
Expand Down Expand Up @@ -84,6 +85,15 @@ export function IntegrationsManager() {
const [selectedDescriptionDraft, setSelectedDescriptionDraft] = useState('')
const [selectedDisplayNameDraft, setSelectedDisplayNameDraft] = useState('')
const [createStep, setCreateStep] = useState<1 | 2>(1)
const createModalContentRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (!showCreateModal || createStep !== 2) return
const id = window.setTimeout(() => {
focusFirstTextInputIn(createModalContentRef.current)
}, 0)
return () => window.clearTimeout(id)
}, [showCreateModal, createStep])
const [serviceSearch, setServiceSearch] = useState('')
Comment thread
TheodoreSpeaks marked this conversation as resolved.
const [copyIdSuccess, setCopyIdSuccess] = useState(false)
const [credentialToDelete, setCredentialToDelete] = useState<WorkspaceCredential | null>(null)
Expand Down Expand Up @@ -769,7 +779,7 @@ export function IntegrationsManager() {
if (!open) resetCreateForm()
}}
>
<ModalContent size='md'>
<ModalContent size='md' ref={createModalContentRef}>
{createStep === 1 ? (
<>
<ModalHeader>Connect Integration</ModalHeader>
Expand Down
1 change: 1 addition & 0 deletions apps/sim/components/emcn/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export {
ModalTitle,
ModalTrigger,
} from './modal/modal'
export { focusFirstTextInput, focusFirstTextInputIn } from './modal/auto-focus'
export {
Popover,
PopoverAnchor,
Expand Down
22 changes: 15 additions & 7 deletions apps/sim/components/emcn/components/modal/auto-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ function isVisible(el: HTMLElement): boolean {
return el.offsetParent !== null || el.getClientRects().length > 0
}

export function focusFirstTextInput(event: Event): void {
const content = event.currentTarget as HTMLElement | null
if (!content) return

const target = Array.from(content.querySelectorAll<HTMLElement>(TEXT_INPUT_SELECTOR)).find(
/**
* Focus the first visible text-entry input within `root`, placing caret at end.
* Returns true if an element was focused.
*/
export function focusFirstTextInputIn(root: HTMLElement | null): boolean {
if (!root) return false
const target = Array.from(root.querySelectorAll<HTMLElement>(TEXT_INPUT_SELECTOR)).find(
isVisible
)
if (!target) return
if (!target) return false

event.preventDefault()
target.focus({ preventScroll: false })

if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
Expand All @@ -49,4 +50,11 @@ export function focusFirstTextInput(event: Event): void {
sel?.removeAllRanges()
sel?.addRange(range)
}
return true
}

export function focusFirstTextInput(event: Event): void {
if (focusFirstTextInputIn(event.currentTarget as HTMLElement | null)) {
event.preventDefault()
}
}