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

187
Visualizações
How to prevent iOS Safari from making unwanted selections?

When I long-press a toolbar button on my React app in iOS Safari it makes a selection of the icon. I disabled it with CSS on the toolbar:

-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;

But then Safari continues selecting the next silly element it can find.

So in I ended up applying the styles to the root of my app, but now of course the user can't select any text in things like paragraphs.

What I really want is a way to put in a barrier that says "Safari, can you please stop trying to select the next thing you may find?"

So on my toolbar component I do this and I verified it gets called:

  onTouchStart={e => {
    e.stopPropagation();
    e.preventDefault();
    e.bubbles = false;
  }}

I also tried this:

  onTouchStartCapture={e => {
    e.stopPropagation();
    e.preventDefault();
    e.bubbles = false;
  }}

And the same with onSelect, onSelectCapture.

However Safari is ignoring all that and keeps on selecting things up the hierarchy all the way to the root DIV until it finds something nonsensical to select. When I look at what it has selected by copying it, it's just a single whitespace.

What am I missing? Do I really have to apply user-select: none; to the root and then selectively allow selection where it makes sense, such as on DIVs that contain text? And then, how will Safari not find and select that when long-pressing the toolbar?

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

0

You can apply the following css, so you can still select <p> and <h> tags:

p {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h1 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h2 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h3 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h4 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h5 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
h6 {
 -webkit-user-select: text !important;
 user-select: text !important;
}
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