Skip to content

Commit

Permalink
feat: accessibilite listbox qui ajoute
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasKhallouk committed Jun 12, 2024
1 parent 8cf4aa2 commit 387b60b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
34 changes: 26 additions & 8 deletions ui/src/backoffice/components/common/page/form/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
import './Select.scss';

const Select = ({
type,
id,
placeholder,
trackingId,
Expand Down Expand Up @@ -57,14 +58,15 @@ const Select = ({

const handleInputKeyDown = event => {
let newFocusedOption;
const optionCount = type === 'create' ? filteredOptions.length + 1 : filteredOptions.length; // +1 for the "Ajouter" option
switch (event.key) {
case 'ArrowDown':
event.preventDefault();
setIsOpen(true);
if (focusedOption === null) {
newFocusedOption = 0;
} else {
newFocusedOption = (focusedOption + 1) % filteredOptions.length;
newFocusedOption = (focusedOption + 1) % optionCount;
}
setFocusedOption(newFocusedOption);
if (optionRefs.current[newFocusedOption]) {
Expand All @@ -78,9 +80,9 @@ const Select = ({
event.preventDefault();
setIsOpen(true);
if (focusedOption === null) {
newFocusedOption = filteredOptions.length - 1;
newFocusedOption = optionCount - 1; // Last option is the "Ajouter" option
} else {
newFocusedOption = (focusedOption - 1 + filteredOptions.length) % filteredOptions.length;
newFocusedOption = (focusedOption - 1 + optionCount) % optionCount;
}
setFocusedOption(newFocusedOption);
if (optionRefs.current[newFocusedOption]) {
Expand All @@ -93,7 +95,11 @@ const Select = ({
case 'Enter':
event.preventDefault();
if (isOpen && focusedOption !== null) {
onChange(filteredOptions[focusedOption]);
if (focusedOption < filteredOptions.length) {
onChange(filteredOptions[focusedOption]);
} else if (type === 'create') {
onChange({ [optionKey]: filter, [optionLabel]: filter });
}
setIsOpen(false);
setFilter('');
}
Expand All @@ -115,7 +121,6 @@ const Select = ({
const handleClear = () => {
setFilter('');
setIsOpen(false);
//inputRef.current.focus();
onChange(null); // Clear the selected value
};

Expand All @@ -128,9 +133,7 @@ const Select = ({
setIsOpen(false);
setFilter('');
}, 100);

};


return (
<div className="combobox combobox-list" ref={comboboxRef}>
Expand Down Expand Up @@ -202,7 +205,22 @@ const Select = ({
</li>
))
) : (
<li className="no-results">Aucun résultat</li>
type === 'create' ? (
<li
key="add-new"
role="option"
aria-selected={focusedOption === filteredOptions.length}
onClick={() => handleOptionClick({ [optionKey]: filter, [optionLabel]: filter })}
className={focusedOption === filteredOptions.length ? 'focused' : ''}
ref={el => {
optionRefs.current[filteredOptions.length] = el;
}}
>
Ajouter "{filter}"
</li>
) : (
<li className="no-results">Aucun résultat</li>
)
)}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class OrganismeForm extends React.Component {
options={store.departements}
optionKey="code"
optionLabel="label"
onChange={(option = {}) => this.setState({ departement: option.code })}
onChange={(option) => this.setState({ departement: option ? option.code : null })}
/>
</div>
<div className="form-group col-lg-6">
Expand All @@ -108,10 +108,12 @@ export default class OrganismeForm extends React.Component {
optionKey="siren"
optionLabel="name"
onChange={(option = {}) => {
this.setState({ siren: option.siren, numeroFormation: null }, () => {
loadFormations(option.siren || account.siret);
const siren = option ? option.siren : undefined;
this.setState({ siren, numeroFormation: null }, () => {
loadFormations(siren || account.siret);
});
}}

/>
</div>
<div className="form-group offset-lg-6 col-lg-6">
Expand All @@ -124,7 +126,7 @@ export default class OrganismeForm extends React.Component {
optionLabel="title"
placeholder={'Toutes les formations'}
trackingId="Formation"
onChange={(option = {}) => this.setState({ numeroFormation: option.numeroFormation })}
onChange={(option) => this.setState({ numeroFormation: option ? option.numeroFormation : null })}
/>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion ui/src/questionnaire/components/Remerciements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Remerciements extends Component {
alt={infosRegion.region.carif.nom} />
</a>
}
{console.log(infosRegion)}
<div>
<a
className="textimage"
Expand Down

0 comments on commit 387b60b

Please sign in to comment.