Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] Stop using custom findIndex to support IE11 #12129

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
* Modified slightly to suit our purposes.
*/

// To replace with .findIndex() once we stop IE11 support.
function findIndex<T>(array: T[], comp: (item: T) => boolean) {
for (let i = 0; i < array.length; i += 1) {
if (comp(array[i])) {
return i;
}
}

return -1;
}

function binaryFindElement(array: TreeItemDescendant[], element: HTMLLIElement) {
let start = 0;
let end = array.length - 1;
Expand Down Expand Up @@ -89,7 +78,7 @@ export function useDescendant(descendant: TreeItemDescendant) {
// index on the following render, and we will re-register descendants
// so that everything is up-to-date before the user interacts with a
// collection.
const index = findIndex(descendants, (item) => item.element === descendant.element);
const index = descendants.findIndex((item) => item.element === descendant.element);

const previousDescendants = usePrevious(descendants);

Expand Down
Loading