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

q-tree with tickable nodes traps the keyboard #17603

Open
chrisnruud opened this issue Oct 28, 2024 · 4 comments
Open

q-tree with tickable nodes traps the keyboard #17603

chrisnruud opened this issue Oct 28, 2024 · 4 comments

Comments

@chrisnruud
Copy link

chrisnruud commented Oct 28, 2024

What happened?

When a q-tree with any tick-strategy is present, it will not tab through the tickable boxes and in fact trap the keyboard.

What did you expect to happen?

I would expect to be able to tab to each checkable item and check them, using the keyboard

Reproduction URL

https://github.com/quasarframework/quasar/blob/dev/docs/src/examples/QTree/TickStrategy.vue

How to reproduce?

  1. Go to the link, try to get focus in one of the checkboxes. try to escape by using tab. Notice how this is not working.

It is the same in the official docs

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Components (quasar), Accessibility [a11y] (quasar)

Platforms/Browsers

Firefox, Chrome

Quasar info output

No response

Relevant log output

No response

Additional context

No response

Copy link

Hi @chrisnruud! 👋

It looks like you provided an invalid or unsupported reproduction URL.
Do not use any service other than Codepen, jsFiddle, StackBlitz, Codesandbox, and GitHub.
Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc.
Please edit your original post above and provide a valid reproduction URL as explained.

Without a proper reproduction, your issue will have to get closed.

Thank you for your collaboration. 👏

@chrisnruud
Copy link
Author

I have updated the link to point at the quasar example code

@Bornstein93
Copy link

Are there any updates on this issue? This seems like a real issue to me and I would like to ask if there is any chance on pushing this.

@chrisnruud chrisnruud changed the title q-tree with ticlable nodes traps the keyboard q-tree with tickable nodes traps the keyboard Jan 14, 2025
@Bornstein93
Copy link

I'm not sure if this is helpfull for patching the quasar QTree component, but at least this plain JavaScript works for me as a temporary workaround. Maybe we can improve it further (I did not put that much effort in the code. Just wanted some fast fix) :

/**
 * Modify checkbox behaviour and fix keyboard trap
 */
function modifyCheckbox() {
  const treeDom = tree.value?.$el as HTMLDivElement | undefined;
  if (!treeDom) return;
  // Get all checkboxes of q-tree
  const checkboxes = treeDom.querySelectorAll('.q-tree__tickbox');
  checkboxes.forEach((box) => {
    if (!(box instanceof HTMLElement)) return;
    const parent = box.parentNode as HTMLElement | null;
    // Hint of what is done on using checkbox
    const title = i18n.global.t('tree.checkboxTitle') || '';
    if (parent?.getAttribute('role') === 'checkbox') {
      // Update existing wrapper attributes
      parent.setAttribute('tabindex', '0');
      parent.setAttribute('title', title);
    } else {
      // Create a wrapper and add attributes
      const wrapper = document.createElement('div');
      wrapper.setAttribute('tabindex', '0');
      wrapper.setAttribute('role', 'checkbox');
      wrapper.setAttribute('title', title);
      // Remove checkbox keyboard trap by excluding actual checkbox from tab sequence
      box.setAttribute('tabindex', '-1');
      // Wrap the checkbox
      if (parent) {
        parent.insertBefore(wrapper, box);
        wrapper.appendChild(box);
      }
      // Click checkbox on pressing Enter
      wrapper.addEventListener('keydown', (event) => {
        if (event.key === 'Enter' || event.key === ' ') {
          event.preventDefault();
          box.click();
          wrapper.focus();
        }
      });
    }
  });
  // Hide the root checkbox if disableRootSelection is enabled
  if (props.disableRootSelection) {
    treeDom
      .querySelector('.q-tree__node-header-content')
      ?.previousElementSibling?.classList.add('hidden');
  }
  // Add tabindex to tree headers to select tree entry via Enter
  const headers = treeDom.querySelectorAll('.q-tree__node-header-content');
  headers.forEach((header) => header.setAttribute('tabindex', '0'));
}

onMounted(modifyCheckbox);
onUpdated(modifyCheckbox);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants