-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/navscroll-review
- Loading branch information
Showing
8 changed files
with
142 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { FC} from 'react'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore non ci sono i types | ||
import BaseAutocomplete from 'accessible-autocomplete/react'; // Reference to https://www.npmjs.com/package/accessible-autocomplete | ||
|
||
export interface AutocompleteAttributes { | ||
/** Identificativo */ | ||
id?: string; | ||
/** Valori chiave - valore all'interno della select */ | ||
source: { value: string; label: string }[]; | ||
/** Placeholder (default: ``) */ | ||
placeholder?: string; | ||
/** Valore di default (default: ``) */ | ||
defaultValue?: string; | ||
/** Modalità display menu (default: `inline`) */ | ||
displayMenu?: string; | ||
/** Funzione ritornante stringa in caso di nessun risultato */ | ||
tNoResults?: () => string; | ||
/** Funzione ritornante stringa di suggerimento */ | ||
tAssistiveHint?: () => string; | ||
/** Funzione ritornante stringa se la query è troppo corta */ | ||
tStatusQueryTooShort?: () => string; | ||
/** Funzione ritornante stringa se non ci sono risultati di ricerca */ | ||
tStatusNoResults?: () => string; | ||
/** Funzione ritornante stringa che identifica l'opzione selezionata */ | ||
tStatusSelectedOption?: () => string; | ||
/** Funzione ritornante stringa che identifica i risultati */ | ||
tStatusResults?: () => string; | ||
/** Classi aggiuntive da usare per il componente Button */ | ||
className?: string; | ||
testId?: string; | ||
} | ||
|
||
|
||
const tAssistiveHintDefault = () => | ||
'Quando i risultati del completamento automatico sono disponibili, usa le frecce su e giù per rivedere e Invio per selezionare. Utenti di dispositivi touch, esplora tramite tocco o con gesti di scorrimento' | ||
const tNoResultsDefault = () => 'Nessun risultato trovato' | ||
const tStatusQueryTooShortDefault = (minQueryLength: number) => `Digita ${minQueryLength} o più caratteri per mostrare le opzioni di ricerca` | ||
const tStatusNoResultsDefault = () => 'Nessun risultato di ricerca' | ||
const tStatusSelectedOptionDefault = (selectedOption: number, length: number, index: number) => `${selectedOption} ${index + 1} di ${length} è sottolineato` | ||
const tStatusResultsDefault = (length: number, contentSelectedOption: number) => { | ||
const words = { | ||
result: length === 1 ? 'risultato' : 'risultati', | ||
is: length === 1 ? 'è' : 'sono', | ||
available: length === 1 ? 'disponibile' : 'disponibili', | ||
} | ||
|
||
return `${length} ${words.result} ${words.is} ${words.available}. ${contentSelectedOption}` | ||
} | ||
|
||
export const Autocomplete: FC<AutocompleteAttributes> = ({ | ||
tAssistiveHint = tAssistiveHintDefault, | ||
tNoResults = tNoResultsDefault, | ||
tStatusQueryTooShort = tStatusQueryTooShortDefault, | ||
tStatusNoResults = tStatusNoResultsDefault, | ||
tStatusSelectedOption = tStatusSelectedOptionDefault, | ||
tStatusResults = tStatusResultsDefault, | ||
placeholder = '', | ||
defaultValue = '', | ||
displayMenu = 'inline', | ||
source, | ||
...attributes | ||
}) => { | ||
|
||
return <BaseAutocomplete | ||
id='autocomplete' | ||
source={source} | ||
placeholder={placeholder} | ||
defaultValue={defaultValue} | ||
displayMenu={displayMenu} | ||
tAssistiveHint = {tAssistiveHint} | ||
tNoResults = {tNoResults} | ||
tStatusQueryTooShort = {tStatusQueryTooShort} | ||
tStatusNoResults = {tStatusNoResults} | ||
tStatusSelectedOption = {tStatusSelectedOption} | ||
tStatusResults = {tStatusResults} | ||
{...attributes} | ||
/>; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
// Focus Management | ||
|
||
/** | ||
* -------------------------------------------------------------------------- | ||
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/) | ||
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS | ||
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE) | ||
* -------------------------------------------------------------------------- | ||
*/ | ||
|
||
const DATA_MOUSE_FOCUS = 'data-focus-mouse' | ||
const CLASS_NAME_MOUSE_FOCUS = 'focus--mouse' | ||
|
||
class TrackFocus { | ||
constructor() { | ||
this._usingMouse = false | ||
|
||
this._bindEvents() | ||
} | ||
|
||
_bindEvents() { | ||
if (typeof document === 'undefined') { | ||
return | ||
} | ||
const events = ['keydown', 'mousedown'] | ||
events.forEach((evtName) => { | ||
document.addEventListener(evtName, (evt) => { | ||
this._usingMouse = evt.type === 'mousedown' | ||
}) | ||
}) | ||
document.addEventListener('focusin', (evt) => { | ||
if (this._usingMouse) { | ||
if (evt.target) { | ||
evt.target.classList.add(CLASS_NAME_MOUSE_FOCUS); | ||
evt.target.setAttribute(DATA_MOUSE_FOCUS, 'true') | ||
} | ||
} | ||
}) | ||
document.addEventListener('focusout', (evt) => { | ||
if (evt.target) { | ||
evt.target.classList.remove(CLASS_NAME_MOUSE_FOCUS); | ||
evt.target.setAttribute(DATA_MOUSE_FOCUS, 'false') | ||
} | ||
}) | ||
} | ||
} | ||
|
||
new TrackFocus() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters