Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
on clicking "/" render a menu and focus on the menu options

I've been working around building a notion-clone and I'm stuck on the feature where if you click "/" then a menu appears which gives out options to change the current block to the preferred one which user selects I'm able to change the block via the menu but I have to use mouse to select an option

const allowedTags = [
    {
      label: "h1",
      value: "heading-one",
    },
    {
      label: "h2",
      value: "heading-tw0",
    },
    {
      label: "quote",
      value: "block-quote",
    },
    {
      label: "numbered",
      value: "numbered-list",
    },
    {
      label: "bullets",
      value: "bulleted-list",
    },
    {
      label: "p",
      value: "paragraph",
    },
  ];

  const renderMenu = () => {
    return (
      <div className="editor__menu" style={coordinates}>
        {allowedTags.map((item, key) => {
          return (
            <p
              className="editor__menu--item"
              key={key}
              onClick={() => {
                CustomEditor.toggleBlock(editor, item.value);
                setMenu(false);
              }}
            >
              {item.label}
            </p>
          );
        })}
      </div>
    );
  };

Here I'm mapping through the allowed tags and creating a list In the editor, if someone types "/" then this menu should come up which is handled by onKeyDown()

 onKeyDown={(event) => {
   if (event.key === "/") {
       openMenu();
   }
 }

enter image description here

Everything works completely fine! But the only thing I'm stuck on is I'm not able to focus on the menu and control it via keyboard keys, can anyone help around this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I advise you to use button tag instead p, h1 or h2. But if there is no other way you can use "tabindex" attribute, like this:

<h1 tabindex="0">Hello</h1>
<p tabindex="0">World</p>

And add this to your function

openMenu();
const element = document.getElementsByClassName('editor__menu--item')[0]
element.focus();

It let focusing on element from keyboard. In addition you can use tabindex="-1" on button if you want to disable focus.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda