Fix search for accessibility view

Summary:
Bug: On search, the accessibility views didn't used to expand.Look at the following video to understand the bug

{F153135892}

Reviewed By: danielbuechele

Differential Revision: D14407511

fbshipit-source-id: 011bf31b5bd10f5a7dad3d5d30703ec3bdeaf9c1
This commit is contained in:
Pritesh Nandgaonkar
2019-03-12 07:05:04 -07:00
committed by Facebook Github Bot
parent 1c8fffa20b
commit 145addf1c9
2 changed files with 50 additions and 14 deletions

View File

@@ -25,6 +25,7 @@ function constructSearchResultTree(
isMatch: boolean, isMatch: boolean,
children: Array<SearchResultTree>, children: Array<SearchResultTree>,
AXMode: boolean, AXMode: boolean,
AXNode: ?Element,
): SearchResultTree { ): SearchResultTree {
let searchResult = { let searchResult = {
id: node.id, id: node.id,
@@ -32,9 +33,8 @@ function constructSearchResultTree(
hasChildren: children.length > 0, hasChildren: children.length > 0,
children: children.length > 0 ? children : null, children: children.length > 0 ? children : null,
element: node, element: node,
axElement: null, axElement: AXNode,
}; };
searchResult[`${propsForPersistedState(AXMode).ELEMENT}`] = node;
return searchResult; return searchResult;
} }
@@ -64,7 +64,15 @@ export function searchNodes(
} }
if (match || children.length > 0) { if (match || children.length > 0) {
return cloneDeep(constructSearchResultTree(node, match, children, AXMode)); return cloneDeep(
constructSearchResultTree(
node,
match,
children,
AXMode,
AXMode ? state.AXelements[node.id] : null,
),
);
} }
return null; return null;
} }

View File

@@ -73,21 +73,29 @@ export default class Search extends Component<Props, State> {
}); });
if (!query) { if (!query) {
this.displaySearchResults({query: '', results: null}); this.displaySearchResults(
{query: '', results: null},
this.props.inAXMode,
);
} else { } else {
this.props.client this.props.client
.call('getSearchResults', {query, axEnabled: this.props.inAXMode}) .call('getSearchResults', {query, axEnabled: this.props.inAXMode})
.then(response => this.displaySearchResults(response)); .then(response =>
this.displaySearchResults(response, this.props.inAXMode),
);
} }
} }
displaySearchResults({ displaySearchResults(
results, {
query, results,
}: { query,
results: ?SearchResultTree, }: {
query: string, results: ?SearchResultTree,
}) { query: string,
},
axMode: boolean,
) {
this.setState({ this.setState({
outstandingSearchQuery: outstandingSearchQuery:
query === this.state.outstandingSearchQuery query === this.state.outstandingSearchQuery
@@ -106,10 +114,30 @@ export default class Search extends Component<Props, State> {
expanded: element.children.some(c => searchResultIDs.has(c)), expanded: element.children.some(c => searchResultIDs.has(c)),
}, },
}), }),
{...this.props.persistedState.elements}, this.props.persistedState.elements,
); );
this.props.setPersistedState({elements}); let {AXelements} = this.props.persistedState;
if (axMode) {
AXelements = searchResults.reduce(
(acc: ElementMap, {axElement}: SearchResultTree) => {
if (!axElement) {
return acc;
}
return {
...acc,
[axElement.id]: {
...axElement,
// expand all search results, that we have have children for
expanded: axElement.children.some(c => searchResultIDs.has(c)),
},
};
},
this.props.persistedState.AXelements,
);
}
this.props.setPersistedState({elements, AXelements});
this.props.onSearchResults({ this.props.onSearchResults({
matches: new Set( matches: new Set(