Skip to content

Commit

Permalink
Fix la navigation au clavier dans les questions
Browse files Browse the repository at this point in the history
  • Loading branch information
johangirod committed Nov 25, 2021
1 parent 342eea4 commit c231a62
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function Conversation({ customEndMessages }: ConversationProps) {
/>
</fieldset>
<Spacing md />
<button aria-hidden className="sr-only" type="submit" tabIndex={-1} />
<Grid container spacing={2}>
{previousAnswers.length > 0 && (
<Grid item xs={6} sm="auto">
Expand All @@ -89,7 +90,11 @@ export default function Conversation({ customEndMessages }: ConversationProps) {
</Grid>
)}
<Grid item xs={6} sm="auto">
<Button size="XS" type="submit" light={!currentQuestionIsAnswered}>
<Button
size="XS"
onPress={goToNextQuestion}
light={!currentQuestionIsAnswered}
>
{currentQuestionIsAnswered ? (
<Trans>Suivant</Trans>
) : (
Expand Down
4 changes: 3 additions & 1 deletion mon-entreprise/source/components/conversation/DateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputProps } from 'Components/conversation/RuleInput'
import { useCallback, useMemo } from 'react'
import { DateField } from 'DesignSystem/field'
import { useCallback, useMemo } from 'react'
import InputSuggestions from './InputSuggestions'

export default function DateInput({
Expand All @@ -10,6 +10,7 @@ export default function DateInput({
title,
onSubmit,
required,
autoFocus,
value,
}: InputProps) {
const dateValue = useMemo(() => {
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function DateInput({
<DateField
label={title}
value={missing ? undefined : dateValue}
autoFocus={autoFocus}
isRequired={required}
onChange={handleDateChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ async function searchCommunes(input: string): Promise<Array<Commune> | null> {
.slice(0, 10)
}

export default function Select({ onChange, value, id, missing }: InputProps) {
export default function Select({
onChange,
value,
id,
missing,
autoFocus,
}: InputProps) {
const [name, setName] = useState(
missing ? '' : formatCommune(value as Commune)
)
Expand Down Expand Up @@ -188,6 +194,7 @@ export default function Select({ onChange, value, id, missing }: InputProps) {
/* role="combobox" // FIXME: Need to use a proper combobox component here */
errorMessage={noResult && <Trans>Cette commune n'existe pas</Trans>}
id={id}
autoFocus={autoFocus}
aria-autocomplete="list"
onBlur={submitFocusedElem}
aria-readonly="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next'
import Worker from './SelectTauxRisque.worker.js'
const worker = new Worker()

function SelectComponent({ onChange, onSubmit, options }) {
function SelectComponent({ onChange, onSubmit, options, autoFocus }) {
const [searchResults, setSearchResults] = useState()
let submitOnChange = (option) => {
onChange(option['Taux net'].replace(',', '.') + '%')
Expand All @@ -23,6 +23,7 @@ function SelectComponent({ onChange, onSubmit, options }) {
<TextField
type="search"
placeholder={t("Saisissez votre domaine d'activité")}
autoFocus={autoFocus}
errorMessage={
searchResults &&
searchResults.length === 0 && <Trans>Aucun résultat</Trans>
Expand Down
2 changes: 1 addition & 1 deletion mon-entreprise/source/design-system/field/DateField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TextField from './TextField'
import { AriaTextFieldOptions } from '@react-aria/textfield'
import TextField from './TextField'

export default function DateField(props: AriaTextFieldOptions) {
return (
Expand Down
1 change: 1 addition & 0 deletions mon-entreprise/source/design-system/field/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function SearchField(
>
{props.isSearchStalled ? <Loader /> : <SearchIcon />}
<SearchInput
{...(props as InputHTMLAttributes<HTMLInputElement>)}
{...(inputProps as InputHTMLAttributes<HTMLInputElement>)}
placeholder={inputProps.placeholder ?? ''}
ref={ref}
Expand Down

0 comments on commit c231a62

Please sign in to comment.