Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⌨️ Keyboard shortcuts/navigation for create and upload #736

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

MontaGhanmy
Copy link
Collaborator

demo_shortcut (online-video-cutter com)

@MontaGhanmy MontaGhanmy self-assigned this Nov 20, 2024
@MontaGhanmy MontaGhanmy linked an issue Nov 20, 2024 that may be closed by this pull request
// translate shortcuts
const translateDynamicShortcut = (shortcut: string): string =>
shortcut.startsWith('CmdOrCtrl+Shift')
? `⇧⌘${shortcut.replace('CmdOrCtrl+Shift+', '')}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this symbol means nothing to non mac users =/ i think we should use https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform to show control if it isn't mac

: shortcut;

if (props.shortcut) {
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the if (shortcut) should be inside the useEffect callback, because useEffect and friends need to always be called in the same exact order and sequence

return () => {
removeShortcut({
shortcut,
handler: event => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function instance will not be the same as the one when added. If the event source tests for the handler it will fail, if it doesn't, this is useless

@@ -58,6 +58,46 @@ export const Button = (props: ButtonProps) => {
else className = className + ' w-9 !p-0 justify-center';
}

// translate shortcuts
const translateDynamicShortcut = (shortcut: string): string =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably be in app/features/global/services/shortcut-service

props.onClick && props.onClick({} as any);
};

const shortcut = props.shortcut || '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inside if (props.shortcut) so it's always truthy here

return (
<div
onClick={props.onClick}
className="flex flex-row p-4 dark:bg-zinc-900 dark:text-white bg-zinc-100 hover:bg-opacity-75 cursor-pointer rounded-md m-2"
className="flex flex-row p-4 dark:bg-zinc-900 dark:text-white bg-zinc-100 hover:bg-opacity-75 cursor-pointer rounded-md m-2 focus:bg-zinc-800 dark:focus:bg-zinc-800 outline-none focus:border-none"
tabIndex={0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the {} and not just 0 ? is this required at all, we're not really doing the tab indexing stuff anywhere else ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tabIndex is a number that's why. It is required for tab to work/navigate the modal items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html dom attribute values are always strings anyway, see https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute . what's happening here is just making react type it first and maybe not guess its a constant it could optimise out

@@ -162,6 +162,7 @@ export default () => {

<Button
onClick={() => uploadItemModal()}
shortcut='CmdOrCtrl+U'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the modifier necessary ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@ericlinagora ericlinagora added this to the v1.0.6 milestone Dec 13, 2024
@MontaGhanmy MontaGhanmy merged commit 57dfbaf into main Dec 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Improve Accessibility
2 participants