Skip to content

Commit

Permalink
[core] Remove some IE11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
iammminzzy committed Mar 23, 2024
1 parent 0102a95 commit 2c8da32
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 59 deletions.
24 changes: 5 additions & 19 deletions packages/mui-base/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import {
} from '@mui/utils';

// https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript
// Give up on IE11 support for this feature
function stripDiacritics(string) {
return typeof string.normalize !== 'undefined'
? string.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
: string;
return string.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}

export function createFilterOptions(config = {}) {
Expand Down Expand Up @@ -56,17 +53,6 @@ export function createFilterOptions(config = {}) {
};
}

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

return -1;
}

const defaultFilterOptions = createFilterOptions();

// Number of options to jump in list box when `Page Up` and `Page Down` keys are used.
Expand Down Expand Up @@ -498,7 +484,7 @@ export function useAutocomplete(props) {
const previousHighlightedOption = previousProps.filteredOptions[highlightedIndexRef.current];

if (previousHighlightedOption) {
return findIndex(filteredOptions, (option) => {
return filteredOptions.findIndex((option) => {
return getOptionLabel(option) === getOptionLabel(previousHighlightedOption);
});
}
Expand Down Expand Up @@ -539,12 +525,12 @@ export function useAutocomplete(props) {
if (
multiple &&
currentOption &&
findIndex(value, (val) => isOptionEqualToValue(currentOption, val)) !== -1
value.findIndex((val) => isOptionEqualToValue(currentOption, val)) !== -1
) {
return;
}

const itemIndex = findIndex(filteredOptions, (optionItem) =>
const itemIndex = filteredOptions.findIndex((optionItem) =>
isOptionEqualToValue(optionItem, valueItem),
);
if (itemIndex === -1) {
Expand Down Expand Up @@ -685,7 +671,7 @@ export function useAutocomplete(props) {
}
}

const itemIndex = findIndex(newValue, (valueItem) => isOptionEqualToValue(option, valueItem));
const itemIndex = newValue.findIndex((valueItem) => isOptionEqualToValue(option, valueItem));

if (itemIndex === -1) {
newValue.push(option);
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-base/src/useSnackbar/useSnackbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export function useSnackbar(parameters: UseSnackbarParameters = {}): UseSnackbar
*/
function handleKeyDown(nativeEvent: KeyboardEvent) {
if (!nativeEvent.defaultPrevented) {
// IE11, Edge (prior to using Blink?) use 'Esc'
if (nativeEvent.key === 'Escape' || nativeEvent.key === 'Esc') {
if (nativeEvent.key === 'Escape') {
// not calling `preventDefault` since we don't know if people may ignore this event e.g. a permanently open snackbar
onClose?.(nativeEvent, 'escapeKeyDown');
}
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-joy/src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
}

function handleKeyDown(nativeEvent: KeyboardEvent) {
// IE11, Edge (prior to using Bink?) use 'Esc'
if (nativeEvent.key === 'Escape' || nativeEvent.key === 'Esc') {
if (nativeEvent.key === 'Escape') {
handleClose(nativeEvent);
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-material/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
* @param {KeyboardEvent} nativeEvent
*/
function handleKeyDown(nativeEvent) {
// IE11, Edge (prior to using Bink?) use 'Esc'
if (nativeEvent.key === 'Escape' || nativeEvent.key === 'Esc') {
if (nativeEvent.key === 'Escape') {
handleClose(nativeEvent);
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/mui-material/src/styles/createTransitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ export default function createTransitions(inputTransitions) {

if (process.env.NODE_ENV !== 'production') {
const isString = (value) => typeof value === 'string';
// IE11 support, replace with Number.isNaN
// eslint-disable-next-line no-restricted-globals
const isNumber = (value) => !isNaN(parseFloat(value));
const isNumber = (value) => !Number.isNaN(parseFloat(value));
if (!isString(props) && !Array.isArray(props)) {
console.error('MUI: Argument "props" must be a string or Array.');
}
Expand Down
12 changes: 1 addition & 11 deletions packages/mui-utils/src/getDisplayName/getDisplayName.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/prefer-stateless-function */
import * as React from 'react';
import { expect } from 'chai';
import getDisplayName, { getFunctionName } from './getDisplayName';
import getDisplayName from './getDisplayName';

describe('utils/getDisplayName.js', () => {
describe('getDisplayName', () => {
Expand Down Expand Up @@ -75,14 +75,4 @@ describe('utils/getDisplayName.js', () => {
expect(getDisplayName(false)).to.equal(undefined);
});
});

describe('getFunctionName', () => {
it('gets the name of a function', () => {
function SomeFunction() {
return <div />;
}

expect(getFunctionName(SomeFunction)).to.equal('SomeFunction');
});
});
});
11 changes: 1 addition & 10 deletions packages/mui-utils/src/getDisplayName/getDisplayName.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import * as React from 'react';
import { ForwardRef, Memo } from 'react-is';

// Simplified polyfill for IE11 support
// https://github.com/JamesMGreene/Function.name/blob/58b314d4a983110c3682f1228f845d39ccca1817/Function.name.js#L3
const fnNameMatchRegex = /^\s*function(?:\s|\s*\/\*.*\*\/\s*)+([^(\s/]*)\s*/;
export function getFunctionName(fn: Function): string {
const match = `${fn}`.match(fnNameMatchRegex);
const name = match && match[1];
return name || '';
}

function getFunctionComponentName(
Component: React.FunctionComponent | React.ComponentClass,
fallback = '',
) {
return Component.displayName || Component.name || getFunctionName(Component) || fallback;
return Component.displayName || Component.name || fallback;
}

function getWrappedName(outerType: any, innerType: any, wrapperName: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/mui-utils/src/getDisplayName/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from './getDisplayName';
export * from './getDisplayName';
10 changes: 1 addition & 9 deletions packages/mui-utils/src/integerPropType/integerPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,10 @@ export function getTypeByValue(value) {
}
}

// IE 11 support
function ponyfillIsInteger(x) {
// eslint-disable-next-line no-restricted-globals
return typeof x === 'number' && isFinite(x) && Math.floor(x) === x;
}

const isInteger = Number.isInteger || ponyfillIsInteger;

function requiredInteger(props, propName, componentName, location) {
const propValue = props[propName];

if (propValue == null || !isInteger(propValue)) {
if (propValue == null || !Number.isInteger(propValue)) {
const propType = getTypeByValue(propValue);

return new RangeError(
Expand Down

0 comments on commit 2c8da32

Please sign in to comment.