Skip to content

Commit

Permalink
More feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanu1 committed Nov 18, 2021
1 parent 13091cc commit 4e6e19b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
9 changes: 6 additions & 3 deletions sample-app/src/components/FilterSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SCREENREADER_INSTRUCTIONS = 'When autocomplete results are available, use
export interface FilterSearchProps {
title: string,
sectioned: boolean,
searchFields: SearchParameterField[],
searchFields: Omit<SearchParameterField, 'fetchEntities'>[],
screenReaderInstructionsId: string
}

Expand All @@ -22,17 +22,20 @@ export default function FilterSearch (props: FilterSearchProps): JSX.Element {
const [results, updateResults] = useState<FilterSearchResponse|undefined>();
const requestId = useRef(0);
const responseId = useRef(0);
const searchParamFields = searchFields.map((searchField) => {
return { ...searchField, fetchEntities: false }
});

async function executeFilterSearch (inputValue: string) {
const currentId = ++requestId.current;
const results = await answersActions.executeFilterSearch(inputValue, sectioned, searchFields);
const results = await answersActions.executeFilterSearch(inputValue, sectioned, searchParamFields);
if (currentId >= responseId.current) {
responseId.current++;
updateResults(results);
}
}

let options: {results: Option[], label?: string}[] = [];
let options: { results: Option[], label?: string }[] = [];
if (results) {
results.sections.forEach(section => {
let results: Option[] = [];
Expand Down
17 changes: 10 additions & 7 deletions sample-app/src/components/InputDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Props {
placeholder?: string,
screenReaderInstructions: string,
screenReaderInstructionsId: string,
options: {results: Option[], label?: string}[],
options: { results: Option[], label?: string }[],
optionIdPrefix: string,
onlySubmitOnOption: boolean,
onSubmit?: (value: string, sectionIndex?: number, optionIndex?: number) => void,
Expand Down Expand Up @@ -89,7 +89,12 @@ export default function InputDropdown({

const screenReaderPhrases: string[] = [];
if (options.length < 1) {
screenReaderPhrases.push(`0 autocomplete options found.`);
const phrase = processTranslation({
phrase: `0 autocomplete option found.`,
pluralForm: `0 autocomplete options found.`,
count: 0
});
screenReaderPhrases.push(phrase);
} else {
options.forEach(section => {
const optionInfo = section.label? `${section.results.length} ${section.label}` : `${section.results.length}`;
Expand Down Expand Up @@ -127,11 +132,9 @@ export default function InputDropdown({
const isLastOptionFocused =
focusedSectionIndex !== undefined &&
focusedOptionIndex === options[focusedSectionIndex].results.length - 1;
if (evt.key === 'Enter') {
if (!onlySubmitOnOption || focusedOptionIndex !== undefined) {
onSubmit(inputValue, focusedSectionIndex, focusedOptionIndex);
dispatch({ type: 'HideOptions' });
}
if (evt.key === 'Enter' && (!onlySubmitOnOption || focusedOptionIndex !== undefined)) {
onSubmit(inputValue, focusedSectionIndex, focusedOptionIndex);
dispatch({ type: 'HideOptions' });
} else if (evt.key === 'Escape' || evt.key === 'Tab') {
dispatch({ type: 'HideOptions' });
} else if (evt.key === 'ArrowDown' && options.length > 0 && !(isLastSectionFocused && isLastOptionFocused)) {
Expand Down
6 changes: 2 additions & 4 deletions sample-app/src/pages/VerticalSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ const staticFiltersGroupLabels = {

const filterSearchFields = [{
fieldApiName: 'builtin.location',
entityType: 'ce_person',
fetchEntities: false
entityType: 'ce_person'
},
{
fieldApiName: 'name',
entityType: 'ce_person',
fetchEntities: false
entityType: 'ce_person'
}];

export default function VerticalSearchPage(props: {
Expand Down

0 comments on commit 4e6e19b

Please sign in to comment.