From fa4d92412d26ea87f27ab6dab5f9b193f687104c Mon Sep 17 00:00:00 2001 From: pierangelomiceli Date: Sat, 20 Feb 2021 14:01:26 +0100 Subject: [PATCH 01/18] traduzione articolo --- 2-ui/4-forms-controls/2-focus-blur/article.md | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/2-ui/4-forms-controls/2-focus-blur/article.md b/2-ui/4-forms-controls/2-focus-blur/article.md index d4348d25b..6c331898e 100644 --- a/2-ui/4-forms-controls/2-focus-blur/article.md +++ b/2-ui/4-forms-controls/2-focus-blur/article.md @@ -1,25 +1,25 @@ # Focusing: focus/blur -An element receives the focus when the user either clicks on it or uses the `key:Tab` key on the keyboard. There's also an `autofocus` HTML attribute that puts the focus onto an element by default when a page loads and other means of getting the focus. +Un elemento riceve il focus sia quando l'utente ci clicca sopra, sia quando usa il tasto `key:Tab` della tastiera. Esiste anche un attributo HTML `autofocus` che mette il focus dentro un elemento di default al caricamento della pagina ed anche altri modi per ottenere il focus. -Focusing on an element generally means: "prepare to accept the data here", so that's the moment when we can run the code to initialize the required functionality. +Porre il focus su un elemento in genere significa: "preparati ad accettare il dato qui", quindi è questo il momento in cui possiamo eseguire il codice per inizializzare la funzionalità richiesta. -The moment of losing the focus ("blur") can be even more important. That's when a user clicks somewhere else or presses `key:Tab` to go to the next form field, or there are other means as well. +Il momento della perdita del focus ("blur") può essere ancora più importante. Si concretizza quando un utente clicca da qualche altra parte o preme il tasto `key:Tab` per andare al prossimo campo del form, ma ci sono altri modi per farlo. -Losing the focus generally means: "the data has been entered", so we can run the code to check it or even to save it to the server and so on. +Perdere il focus generalmente significa: "il dato è stato inserito", quindi possiamo eseguire il codice per controllarlo oppure salvarlo sul server e così via. -There are important peculiarities when working with focus events. We'll do the best to cover them further on. +Ci sono delle peculiarità importanti da considerare quando si lavora con gli eventi focus. Faremo il nostro meglio per affrontarle più avanti. -## Events focus/blur +## Gli eventi focus/blur -The `focus` event is called on focusing, and `blur` -- when the element loses the focus. +L'evento `focus` viene chiamato quando si entra dentro un elemento (focusing), e `blur` -- quando l'elemento perde il focus. -Let's use them for validation of an input field. +Ora proviamoli per la validazione di un campo di input. -In the example below: +Nell'esempio seguente: -- The `blur` handler checks if the field has an email entered, and if not -- shows an error. -- The `focus` handler hides the error message (on `blur` it will be checked again): +- Il gestore `blur` controlla se il campo contiene un indirizzo email, altrimenti -- mostra un errore. +- Il gestore `focus` nasconde il messaggio d'errore (sul `blur` verrà controllato nuovamente): ```html run autorun height=60 -Your email please: +Inserire la mail:
``` -Modern HTML allows us to do many validations using input attributes: `required`, `pattern` and so on. And sometimes they are just what we need. JavaScript can be used when we want more flexibility. Also we could automatically send the changed value to the server if it's correct. +Il codice HTML moderno, ci permette di eseguire diverse validazioni tramite gli attributi degli input: `required`, `pattern` e così via. E talvolta sono sufficienti per le nostre esigenze. JavaScript può essere usato se vogliamo più flessibilità. Inoltre potremmo voler inviare in automatico il valore al server nel caso sia corretto. -## Methods focus/blur +## I metodi focus/blur -Methods `elem.focus()` and `elem.blur()` set/unset the focus on the element. +I metodi `elem.focus()` e `elem.blur()` attivano/disattivano il focus su un elemento. -For instance, let's make the visitor unable to leave the input if the value is invalid: +Per esempio, facciamo in modo che l'utente non possa spostarsi da un input fintanto che il valore sia scorretto: ```html run autorun height=80 -Your email please: - +La tua email: + ``` -It works in all browsers except Firefox ([bug](https://bugzilla.mozilla.org/show_bug.cgi?id=53579)). +Funziona su tutti i browser tranne che su Firefox ([bug](https://bugzilla.mozilla.org/show_bug.cgi?id=53579)). -If we enter something into the input and then try to use `key:Tab` or click away from the ``, then `onblur` returns the focus back. +Se inseriamo qualcosa nell'input e proviamo ad usare `key:Tab` o cliccare fuori dall'input ``, `onblur` rimette il focus sull'input. -Please note that we can't "prevent losing focus" by calling `event.preventDefault()` in `onblur`, because `onblur` works *after* the element lost the focus. +Nota bene che non possiamo "prevenire la perdita del focus" chiamando `event.preventDefault()` su `onblur`, perché `onblur` viene creato *dopo* che l'elemento per il focus. -```warn header="JavaScript-initiated focus loss" -A focus loss can occur for many reasons. +```warn header="Perdita del focus creata tramite JavaScript" +La perdita del focus può avvenire per varie ragioni. -One of them is when the visitor clicks somewhere else. But also JavaScript itself may cause it, for instance: +Una di queste è quando il visitatore clicca da qualche altra parte. Ma anche JavaScript stesso può causarlo, per esempio: -- An `alert` moves focus to itself, so it causes the focus loss at the element (`blur` event), and when the `alert` is dismissed, the focus comes back (`focus` event). -- If an element is removed from DOM, then it also causes the focus loss. If it is reinserted later, then the focus doesn't return. +- Un `alert` sposta il focus su sé stesso, questo causa la perdita del focus sull'elemento (evento `blur`), e quando l'`alert` viene dismesso, il focus ritorna sull'elemento (evento `focus`). +- La rimozione di un elemento dal DOM, causa essa stessa la perdita del ficus. Nel caso in cui venga reinserito, ovviamente il focus non ritornerà su di esso. -These features sometimes cause `focus/blur` handlers to misbehave -- to trigger when they are not needed. +Queste caratteristiche causano, nei gestori `focus/blur`, dei comportamenti inattesi -- a scatenarsi quando non richiesto. -The best recipe is to be careful when using these events. If we want to track user-initiated focus-loss, then we should avoid causing it ourselves. +La pratica migliore è quella di fare attenzione nell'uso di questi eventi. Se vogliamo tenere traccia della perdita del focus causata volontariamente dall'utente, dovremmo evitare di causarla noi stessi. ``` -## Allow focusing on any element: tabindex +## Permettere il focus su ogni elemento: tabindex -By default many elements do not support focusing. +Di default c'è una varietà di elementi che non supporta il focus. -The list varies a bit between browsers, but one thing is always correct: `focus/blur` support is guaranteed for elements that a visitor can interact with: `