Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added autocomplete component #973

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions stories/Form/Input.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ Cerca una regione italiana per verificarne il comportamento.
<Story id='componenti-form-input--input-autocomplete-con-dati' />
</Canvas>

### Autocompletamento Accessibile con dati

Il completamento automatico è un componente che aiuta gli utenti a scegliere le risposte da un elenco fornito.

Per la creazione del componente, è stato utilizzato il plugin <a target="_blank" href="https://github.com/alphagov/accessible-autocomplete">Accessible autocomplete</a>.

Per una corretta implementazione si consiglia di consultare la <a target="_blank" href="https://alphagov.github.io/accessible-autocomplete/">documentazione</a>.
<Canvas>
<Story id='componenti-form-input--input-autocomplete-con-dati-accessibile' />
</Canvas>

## Area di testo

Per permettere agli utenti di inserire del testo (ad esempio per lasciare commenti o informazioni), è bene utilizzare un elemento di tipo `<textarea>` ridimensionabile.
Expand Down
36 changes: 36 additions & 0 deletions stories/Form/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { multiOptions } from './Autocomplete/AutocompleteExample';

import { Input, TimeInput, Icon, TextArea, FormGroup } from '../../src';

import Autocomplete from 'accessible-autocomplete/react';
import 'accessible-autocomplete/dist/accessible-autocomplete.min.css';

export default {
title: 'Componenti/Form/Input'
};
Expand Down Expand Up @@ -36,6 +39,7 @@ export const EsempiDiCampiDiInput = () => {
isValid ? 'Campo di tipo ora - dark' : 'Formato ora non valido (hh:mm)'
);
};

return (
<div>
<Input type='text' label='Campo di tipo testuale' id='exampleInputText' />
Expand Down Expand Up @@ -356,6 +360,38 @@ export const _InputAutocompleteConDati = () => {

_InputAutocompleteConDati.storyName = 'Input autocomplete';

export const _InputAutocompleteConDatiAccessibile = () => {
// @ts-ignore
const suggest = (query, populateResults) => {
const filteredResults = multiOptions.filter((i) =>
i.label.toLowerCase().includes(query.toLowerCase())
);
let data = filteredResults.map((item) => {
return item.label;
});
populateResults(data);
};

return (
<FormGroup>
<label htmlFor='autocomplete'>Provincia</label>
<Autocomplete
id='autocomplete'
source={suggest}
autoselect
placeholder={'Testo da cercare'}
defaultValue={''}
className={''}
displayMenu={'overlay'}
tNoResults={() => 'Nessun risultato'}
/>
</FormGroup>
);
};

_InputAutocompleteConDatiAccessibile.storyName =
'Input autocomplete accessibile';

export const AreaDiTesto = () => (
<TextArea label='Esempio di area di testo' rows={3} />
);
Expand Down
Loading