Skip to content

Commit

Permalink
Fix focus when entering modal dropdown. (#547)
Browse files Browse the repository at this point in the history
this PR fixes a problem initially solved in #276, unfortunately the
previous approach prevented us from autofocusing on input fields in
modals when opening modals for the first time, as it kept focus on the
background.
  • Loading branch information
filip131311 authored Sep 17, 2024
1 parent 8faa37d commit e569b2f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ButtonProps {
type?: "primary" | "secondary";
};
className?: string;
autoFocus: boolean;
}

function Button({
Expand All @@ -26,9 +27,11 @@ function Button({
disabled,
active,
tooltip,
autoFocus,
}: ButtonProps) {
const button = (
<button
autoFocus={autoFocus}
onClick={onClick}
disabled={disabled}
className={classNames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export default function Modal({ title, component, open, setOpen, headerShown }:
<Dialog.Root open={open}>
<Dialog.Portal>
<Dialog.Overlay className="modal-overlay" onClick={close} />
<Dialog.Content
className="modal-content"
onEscapeKeyDown={close}
onOpenAutoFocus={preventDefault}>
<Dialog.Content className="modal-content" onEscapeKeyDown={close}>
{headerShown && <Dialog.Title className="modal-title">{title}</Dialog.Title>}

<div className="modal-content-container">{component}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function ManageDevicesView() {
))}
</>
)}
<Button className="create-button" onClick={() => setCreateDeviceViewOpen(true)}>
<Button autoFocus className="create-button" onClick={() => setCreateDeviceViewOpen(true)}>
<span className="codicon codicon-add" />
<div className="create-button-text">Create new device</div>
</Button>
Expand Down

0 comments on commit e569b2f

Please sign in to comment.