From 9e20b20215020e65b47bd2d49bc44479f7ff74ed Mon Sep 17 00:00:00 2001 From: Govinda Raj Date: Tue, 12 Mar 2024 11:40:23 +0530 Subject: [PATCH 1/2] fix(cascader): typo in docs --- docs/pages/components/cascader/en-US/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/components/cascader/en-US/index.md b/docs/pages/components/cascader/en-US/index.md index 7d1548b045..4bae302bfc 100644 --- a/docs/pages/components/cascader/en-US/index.md +++ b/docs/pages/components/cascader/en-US/index.md @@ -48,7 +48,7 @@ This tree allows the use of the `getChildren` option and the length of the child -### Contorlled +### Controlled From 5e022aa53db55753cd27d7874fd8c3d5af249a30 Mon Sep 17 00:00:00 2001 From: Govinda Raj Date: Mon, 18 Mar 2024 03:12:27 +0530 Subject: [PATCH 2/2] refactor(substr): replaced deprecated substr method with substring --- src/MaskedInput/adjustCaretPosition.ts | 34 ++++++++++++++------------ src/MaskedInput/conformToMask.ts | 4 +-- src/styles/plugins/palette.js | 3 ++- src/utils/guid.ts | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/MaskedInput/adjustCaretPosition.ts b/src/MaskedInput/adjustCaretPosition.ts index 6fd13ad4a1..32ab33b542 100644 --- a/src/MaskedInput/adjustCaretPosition.ts +++ b/src/MaskedInput/adjustCaretPosition.ts @@ -74,7 +74,9 @@ export default function adjustCaretPosition({ const normalizedRawValue = rawValue.toLowerCase(); // Then we take all characters that come before where the caret currently is. - const leftHalfChars = normalizedRawValue.substr(0, currentCaretPosition).split(emptyString); + const leftHalfChars = normalizedRawValue + .substring(0, currentCaretPosition + 2) + .split(emptyString); // Now we find all the characters in the left half that exist in the conformed input // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`. @@ -89,14 +91,14 @@ export default function adjustCaretPosition({ // Calculate the number of mask characters in the previous placeholder // from the start of the string up to the place where the caret is const previousLeftMaskChars = previousPlaceholder - .substr(0, intersection.length) + .substring(0, intersection.length + 2) .split(emptyString) .filter(char => char !== placeholderChar).length; // Calculate the number of mask characters in the current placeholder // from the start of the string up to the place where the caret is const leftMaskChars = placeholder - .substr(0, intersection.length) + .substring(0, intersection.length + 2) .split(emptyString) .filter(char => char !== placeholderChar).length; @@ -143,18 +145,20 @@ export default function adjustCaretPosition({ // We need to know if the placeholder contains characters that look like // our `targetChar`, so we don't select one of those by mistake. - const countTargetCharInPlaceholder = placeholder - .substr(0, placeholder.indexOf(placeholderChar)) - .split(emptyString) - .filter( - (char, index) => - // Check if `char` is the same as our `targetChar`, so we account for it - char === targetChar && - // but also make sure that both the `rawValue` and placeholder don't have the same character at the same - // index because if they are equal, that means we are already counting those characters in - // `countTargetCharInIntersection` - rawValue[index] !== char - ).length; + + const placeholderIndex = placeholder.indexOf(placeholderChar); + const endIndex = placeholderIndex !== -1 ? placeholderIndex + 2 : -1; + const extractedSubstring = endIndex !== -1 ? placeholder.substring(0, endIndex) : ''; + + const countTargetCharInPlaceholder = extractedSubstring.split(emptyString).filter( + (char, index) => + // Check if `char` is the same as our `targetChar`, so we account for it + char === targetChar && + // but also make sure that both the `rawValue` and placeholder don't have the same character at the same + // index because if they are equal, that means we are already counting those characters in + // `countTargetCharInIntersection` + rawValue[index] !== char + ).length; // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking // for is: diff --git a/src/MaskedInput/conformToMask.ts b/src/MaskedInput/conformToMask.ts index 602906a493..e03c5d9b4c 100644 --- a/src/MaskedInput/conformToMask.ts +++ b/src/MaskedInput/conformToMask.ts @@ -209,7 +209,7 @@ export default function conformToMask( // // That is, for mask `(111)` and user input `2`, we want to return `(2`, not `(2__)`. if (suppressGuide === false) { - conformedValue += placeholder.substr(i, placeholderLength); + conformedValue += placeholder.substring(i, placeholderLength + 2); } // And we break @@ -240,7 +240,7 @@ export default function conformToMask( if (indexOfLastFilledPlaceholderChar !== null) { // We substring from the beginning until the position after the last filled placeholder char. - conformedValue = conformedValue.substr(0, indexOfLastFilledPlaceholderChar + 1); + conformedValue = conformedValue.substring(0, indexOfLastFilledPlaceholderChar + 3); } else { // If we couldn't find `indexOfLastFilledPlaceholderChar` that means the user deleted // the first character in the mask. So we return an empty string. diff --git a/src/styles/plugins/palette.js b/src/styles/plugins/palette.js index 504e8b60ed..8ca0098869 100644 --- a/src/styles/plugins/palette.js +++ b/src/styles/plugins/palette.js @@ -379,7 +379,8 @@ var tinycolor = (function (Math) { if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { rgb = rgbToRgb(color.r, color.g, color.b); ok = true; - format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb'; + const colorString = String(color.r); + format = colorString.substring(colorString.length - 1) === '%' ? 'prgb' : 'rgb'; } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { s = convertToPercentage(color.s); v = convertToPercentage(color.v); diff --git a/src/utils/guid.ts b/src/utils/guid.ts index ccb6d1609a..b3a688a189 100644 --- a/src/utils/guid.ts +++ b/src/utils/guid.ts @@ -1,3 +1,3 @@ export default function guid() { - return '_' + Math.random().toString(36).substr(2, 12); + return '_' + Math.random().toString(36).substring(2, 14); }