Skip to content

Commit

Permalink
Autofocus buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Apr 11, 2023
1 parent a38691e commit 66813d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports = {
"plugin:@typescript-eslint/recommended",
"eslint-config-prettier"
],
parser: '@typescript-eslint/parser',
parser: "@typescript-eslint/parser",
parserOptions: {
project: ['./tsconfig.json'],
project: ["./tsconfig.json"]
},
ignorePatterns: ["src-tauri/**/*"],
settings: {
Expand All @@ -25,13 +25,13 @@ module.exports = {
}
},
rules: {
"jsx-a11y/no-autofocus": "warn",
"jsx-a11y/no-autofocus": "off",
"react/react-in-jsx-scope": "off",
"import/no-unresolved": "off",
"@typescript-eslint/consistent-type-imports": ["error", {
prefer: "type-imports",
disallowTypeAnnotations: true,
fixStyle: "separate-type-imports"
}],
}]
}
};
19 changes: 10 additions & 9 deletions src-web/components/WorkspaceActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,26 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceDropdown({ classN
<Button
className="focus"
color="gray"
rightSlot={<Icon icon="openNewWindow" />}
onClick={async () => {
onClick={() => {
hide();
await invoke('new_window', {
url: routes.paths.workspace({ workspaceId: w.id }),
});
routes.navigate('workspace', { workspaceId: w.id });
}}
>
New Window
This Window
</Button>
<Button
autoFocus
className="focus"
color="gray"
onClick={() => {
rightSlot={<Icon icon="openNewWindow" />}
onClick={async () => {
hide();
routes.navigate('workspace', { workspaceId: w.id });
await invoke('new_window', {
url: routes.paths.workspace({ workspaceId: w.id }),
});
}}
>
This Window
New Window
</Button>
</HStack>
);
Expand Down
8 changes: 1 addition & 7 deletions src-web/hooks/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ const confirmButtonTexts: Record<NonNullable<ConfirmProps['variant']>, string> =
};

export function Confirm({ onHide, onResult, variant = 'confirm' }: ConfirmProps) {
const focusRef = (el: HTMLButtonElement | null) => {
setTimeout(() => {
el?.focus();
});
};

const handleHide = () => {
onResult(false);
onHide();
Expand All @@ -40,7 +34,7 @@ export function Confirm({ onHide, onResult, variant = 'confirm' }: ConfirmProps)
<Button className="focus" color="gray" onClick={handleHide}>
Cancel
</Button>
<Button className="focus" ref={focusRef} color={colors[variant]} onClick={handleSuccess}>
<Button autoFocus className="focus" color={colors[variant]} onClick={handleSuccess}>
{confirmButtonTexts[variant]}
</Button>
</HStack>
Expand Down

0 comments on commit 66813d6

Please sign in to comment.