vizhub-core / vzcode

Mob Programming Code Editor
MIT License
58 stars 13 forks source link

Keyboard Navigation & Accessibility #176

Open curran opened 11 months ago

curran commented 11 months ago

As a user, it should be possible to switch between files using the keyboard.

curran commented 9 months ago

Some insights from ChatGPT:

Making the interface accessible involves a few key principles, such as ensuring keyboard navigability, providing visual feedback, and supporting assistive technologies. Here's a breakdown of suggestions for each of the files you've provided:

DirectoryListing.tsx and FileListing.tsx

Item.tsx

Listing.tsx

index.tsx

styles.scss

General Tips

You might also consider using existing libraries or frameworks that come with built-in accessibility features to help ensure that your interface is compliant with standards like WCAG (Web Content Accessibility Guidelines).

Finally, involve users with disabilities in your testing process to get real-world feedback on the accessibility of your interface.

curran commented 9 months ago

Prompt:

Is it possible to leverage react-aria for this? How would that look?

Response from ChatGPT:

Yes, react-aria is a library from Adobe that provides hooks that manage the state and interactions for common accessibility patterns. It can be very helpful in making your interface more accessible. Here's how you can leverage react-aria with the components you've provided:

Using react-aria with DirectoryListing.tsx and FileListing.tsx

For DirectoryListing.tsx and FileListing.tsx, you could use useButton from react-aria to handle button interactions. This will ensure that buttons are accessible and have the correct ARIA attributes.

import { useButton } from 'react-aria';

...

const { buttonProps } = useButton({
  onPress: handleClick,
  elementType: 'div'
}, ref);

...

<div {...buttonProps} className="file-or-directory">
  {name}
</div>

Using react-aria with Item.tsx

Item.tsx can benefit from useTextField for the renaming functionality, which will make sure that the text field is fully accessible, handling focus events and ARIA attributes.

import { useTextField } from 'react-aria';

...

let { inputProps } = useTextField({
  type: 'text',
  onChange: setRenameValue,
  onKeyDown,
  onBlur
}, renameInputRef);

...

{isRenaming ? (
  <input
    {...inputProps}
    ref={renameInputRef}
    value={renameValue}
  />
) : (
  children
)}

Using react-aria with Listing.tsx

For handling the toggle functionality in Listing.tsx, you could use useToggle from react-aria. This hook is great for managing state for toggle-able components, ensuring the correct ARIA attributes are applied.

import { useToggle } from 'react-aria';

...

const { toggleProps } = useToggle({
  isPressed: isOpen,
  onPress: toggleDirectory
});

...

<div {...toggleProps} className="directory-name">
  {name}
</div>

Using react-aria with index.tsx

In index.tsx, you could use useDialog to manage the create file modal, ensuring that focus is managed correctly and the modal is accessible.

import { useDialog } from 'react-aria';

...

let { dialogProps, titleProps } = useDialog({}, ref);

...

<CreateFileModal
  {...dialogProps}
  titleProps={titleProps}
  show={isModalOpen}
  onClose={handleCloseModal}
  onRename={handleRename}
/>

General Implementations with react-aria

By using react-aria, you can ensure that the interactions in your UI components meet the accessibility standards and behave as expected for users of assistive technologies. Remember to follow the documentation for each hook to understand the expected structure of the HTML elements and how to spread the provided props correctly.