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

206
Visualizações
How to apply FocusIn and FocusOut as a whole for the primeng tree

Scenario: I have a primeng tree inside a div component. So when I click any of the tree nodes, then focusin should be triggered once (even if I click another node, shouldn't trigger focusin because it's already clicked inside the div)and only when I click outside of the tree node's div should trigger the focusout.

What's Happening: Whenever I click the node, focusin is triggered and if I click another node inside the same tree, then focusout is triggered first and focusin is triggered next.

Here is the code:

.html

<div (focusin)="onFocusIn()" (focusout)="onFocusOut()">
  <p-tree [value]="files1"></p-tree>
</div>

.ts

  onFocusIn() {
    console.log('Focus In');
  }

  onFocusOut() {
    console.log('Focus Out');
  }

Here is the stackblitz link

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

0

You can merge two events and get last of focus operation, this is will be an action what you need:

const focusOut = fromEvent(this.divRef.nativeElement, 'focusout');
const focusIn = fromEvent(this.divRef.nativeElement, 'focusin');

merge(focusOut, focusIn)
  .pipe(debounceTime(0))
  .subscribe((e: any) => {
    if (e?.type === 'focusin') {
       this.onFocusIn();
    } else {
       this.onFocusOut();
    }
  });

Also an example with working code, hope this helps. Stackblitz

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