Skip to content

Commit

Permalink
Use map
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanu1 committed Nov 18, 2021
1 parent 4e6e19b commit 151f5b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion sample-app/src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function Dropdown({

return (
<div className={cssClasses.optionContainer}>
{options.map((section, sectionIndex) => renderSection(section, sectionIndex))}
{options.map(renderSection)}
</div>
);
};
20 changes: 9 additions & 11 deletions sample-app/src/components/FilterSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ export default function FilterSearch (props: FilterSearchProps): JSX.Element {

let options: { results: Option[], label?: string }[] = [];
if (results) {
results.sections.forEach(section => {
let results: Option[] = [];
section.results.forEach(result => {
results.push({
value: result.value,
render: () => renderWithHighlighting(result)
});
});
options.push({
results: results,
options = results.sections.map(section => {
return {
results: section.results.map(result => {
return {
value: result.value,
render: () => renderWithHighlighting(result)
};
}),
label: section.label
});
};
});
}

Expand Down
12 changes: 5 additions & 7 deletions sample-app/src/components/InputDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,24 @@ export default function InputDropdown({
setScreenReaderKey(0);
}

const screenReaderPhrases: string[] = [];
let screenReaderText = '';
if (options.length < 1) {
const phrase = processTranslation({
screenReaderText = processTranslation({
phrase: `0 autocomplete option found.`,
pluralForm: `0 autocomplete options found.`,
count: 0
});
screenReaderPhrases.push(phrase);
} else {
options.forEach(section => {
const screenReaderPhrases = options.map(section => {
const optionInfo = section.label? `${section.results.length} ${section.label}` : `${section.results.length}`;
const phrase = processTranslation({
return processTranslation({
phrase: `${optionInfo} autocomplete option found.`,
pluralForm: `${optionInfo} autocomplete options found.`,
count: section.results.length
});
screenReaderPhrases.push(phrase);
});
screenReaderText = screenReaderPhrases.join(' ');
}
const screenReaderText = screenReaderPhrases.join(' ');

function handleDocumentClick(evt: MouseEvent) {
const target = evt.target as HTMLElement;
Expand Down

0 comments on commit 151f5b7

Please sign in to comment.