@dnb/eufemia 10.71.0 → 10.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/cjs/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/cjs/components/date-picker/DatePickerFooter.js.map +1 -1
- package/cjs/components/date-picker/DatePickerInput.js +18 -22
- package/cjs/components/date-picker/DatePickerInput.js.map +1 -1
- package/cjs/components/date-picker/hooks/useDates.d.ts +1 -10
- package/cjs/components/date-picker/hooks/useDates.js +2 -40
- package/cjs/components/date-picker/hooks/useDates.js.map +1 -1
- package/cjs/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/cjs/components/date-picker/hooks/useInputDates.js +80 -0
- package/cjs/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/cjs/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/cjs/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/cjs/components/tooltip/TooltipContainer.js +2 -1
- package/cjs/components/tooltip/TooltipContainer.js.map +1 -1
- package/cjs/extensions/forms/utils/FormError.d.ts +3 -0
- package/cjs/extensions/forms/utils/FormError.js.map +1 -1
- package/cjs/shared/Eufemia.d.ts +1 -1
- package/cjs/shared/Eufemia.js +2 -2
- package/cjs/shared/Eufemia.js.map +1 -1
- package/cjs/shared/locales/en-GB.js +2 -2
- package/cjs/shared/locales/en-GB.js.map +1 -1
- package/cjs/style/core/scopes.scss +1 -1
- package/cjs/style/dnb-ui-basis.css +1 -1
- package/cjs/style/dnb-ui-basis.min.css +1 -1
- package/cjs/style/dnb-ui-body.css +1 -1
- package/cjs/style/dnb-ui-body.min.css +1 -1
- package/cjs/style/dnb-ui-core.css +1 -1
- package/cjs/style/dnb-ui-core.min.css +1 -1
- package/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/components/date-picker/DatePickerFooter.js.map +1 -1
- package/components/date-picker/DatePickerInput.js +18 -22
- package/components/date-picker/DatePickerInput.js.map +1 -1
- package/components/date-picker/hooks/useDates.d.ts +1 -10
- package/components/date-picker/hooks/useDates.js +2 -36
- package/components/date-picker/hooks/useDates.js.map +1 -1
- package/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/components/date-picker/hooks/useInputDates.js +72 -0
- package/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/components/tooltip/TooltipContainer.js +2 -1
- package/components/tooltip/TooltipContainer.js.map +1 -1
- package/es/components/date-picker/DatePickerFooter.d.ts +2 -2
- package/es/components/date-picker/DatePickerFooter.js.map +1 -1
- package/es/components/date-picker/DatePickerInput.js +18 -22
- package/es/components/date-picker/DatePickerInput.js.map +1 -1
- package/es/components/date-picker/hooks/useDates.d.ts +1 -10
- package/es/components/date-picker/hooks/useDates.js +2 -36
- package/es/components/date-picker/hooks/useDates.js.map +1 -1
- package/es/components/date-picker/hooks/useInputDates.d.ts +14 -0
- package/es/components/date-picker/hooks/useInputDates.js +70 -0
- package/es/components/date-picker/hooks/useInputDates.js.map +1 -0
- package/es/components/input-masked/text-mask/adjustCaretPosition.js +2 -2
- package/es/components/input-masked/text-mask/adjustCaretPosition.js.map +1 -1
- package/es/components/tooltip/TooltipContainer.js +2 -1
- package/es/components/tooltip/TooltipContainer.js.map +1 -1
- package/es/extensions/forms/utils/FormError.d.ts +3 -0
- package/es/extensions/forms/utils/FormError.js.map +1 -1
- package/es/shared/Eufemia.d.ts +1 -1
- package/es/shared/Eufemia.js +2 -2
- package/es/shared/Eufemia.js.map +1 -1
- package/es/shared/locales/en-GB.js +2 -2
- package/es/shared/locales/en-GB.js.map +1 -1
- package/es/style/core/scopes.scss +1 -1
- package/es/style/dnb-ui-basis.css +1 -1
- package/es/style/dnb-ui-basis.min.css +1 -1
- package/es/style/dnb-ui-body.css +1 -1
- package/es/style/dnb-ui-body.min.css +1 -1
- package/es/style/dnb-ui-core.css +1 -1
- package/es/style/dnb-ui-core.min.css +1 -1
- package/esm/dnb-ui-basis.min.mjs +1 -1
- package/esm/dnb-ui-components.min.mjs +1 -1
- package/esm/dnb-ui-elements.min.mjs +1 -1
- package/esm/dnb-ui-extensions.min.mjs +1 -1
- package/esm/dnb-ui-lib.min.mjs +1 -1
- package/extensions/forms/utils/FormError.d.ts +3 -0
- package/extensions/forms/utils/FormError.js.map +1 -1
- package/package.json +1 -1
- package/shared/Eufemia.d.ts +1 -1
- package/shared/Eufemia.js +2 -2
- package/shared/Eufemia.js.map +1 -1
- package/shared/locales/en-GB.js +2 -2
- package/shared/locales/en-GB.js.map +1 -1
- package/style/core/scopes.scss +1 -1
- package/style/dnb-ui-basis.css +1 -1
- package/style/dnb-ui-basis.min.css +1 -1
- package/style/dnb-ui-body.css +1 -1
- package/style/dnb-ui-body.min.css +1 -1
- package/style/dnb-ui-core.css +1 -1
- package/style/dnb-ui-core.min.css +1 -1
- package/umd/dnb-ui-basis.min.js +1 -1
- package/umd/dnb-ui-components.min.js +1 -1
- package/umd/dnb-ui-elements.min.js +1 -1
- package/umd/dnb-ui-extensions.min.js +1 -1
- package/umd/dnb-ui-lib.min.js +1 -1
- package/cjs/components/icon/lib/SvgComparison.d.ts +0 -2
- package/cjs/components/icon/lib/SvgComparison.js +0 -56
- package/cjs/components/icon/lib/SvgComparison.js.map +0 -1
- package/components/icon/lib/SvgComparison.d.ts +0 -2
- package/components/icon/lib/SvgComparison.js +0 -49
- package/components/icon/lib/SvgComparison.js.map +0 -1
- package/es/components/icon/lib/SvgComparison.d.ts +0 -2
- package/es/components/icon/lib/SvgComparison.js +0 -49
- package/es/components/icon/lib/SvgComparison.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adjustCaretPosition.js","names":["defaultArray","emptyString","adjustCaretPosition","_ref","previousConformedValue","previousPlaceholder","currentCaretPosition","conformedValue","rawValue","placeholderChar","placeholder","indexesOfPipedChars","caretTrapIndexes","keepCharPositions","length","rawValueLength","previousConformedValueLength","placeholderLength","conformedValueLength","editLength","isAddition","isFirstRawValue","isPartialMultiCharEdit","possiblyHasRejectedChar","startingSearchIndex","trackRightCharacter","targetChar","normalizedConformedValue","toLowerCase","normalizedRawValue","leftHalfChars","substr","split","intersection","filter","char","indexOf","previousLeftMaskChars","leftMaskChars","masklengthChanged","targetIsMaskMovingLeft","undefined","pipedChars","map","index","countTargetCharInPipedChars","countTargetCharInIntersection","countTargetCharInPlaceholder","requiredNumberOfMatches","numberOfEncounteredMatches","i","conformedValueChar","lastPlaceholderChar"],"sources":["../../../../../src/components/input-masked/text-mask/adjustCaretPosition.js"],"sourcesContent":["const defaultArray = []\nconst emptyString = ''\n\nexport default function adjustCaretPosition({\n previousConformedValue = emptyString,\n previousPlaceholder = emptyString,\n currentCaretPosition = 0,\n conformedValue,\n rawValue,\n placeholderChar,\n placeholder,\n indexesOfPipedChars = defaultArray,\n caretTrapIndexes = defaultArray,\n keepCharPositions = false,\n}) {\n if (currentCaretPosition === 0 || !rawValue.length) {\n return 0\n }\n\n // Store lengths for faster performance?\n const rawValueLength = rawValue.length\n const previousConformedValueLength = previousConformedValue.length\n const placeholderLength = placeholder.length\n const conformedValueLength = conformedValue.length\n\n // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,\n // we know the user in this instance pasted two characters\n const editLength = rawValueLength - previousConformedValueLength\n\n // If the edit length is positive, that means the user is adding characters, not deleting.\n const isAddition = editLength > 0\n\n // This is the first raw value the user entered that needs to be conformed to mask\n const isFirstRawValue = previousConformedValueLength === 0\n\n // A partial multi-character edit happens when the user makes a partial selection in their\n // input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by\n // selecting the first 3 digits and pressing backspace.\n //\n // Such cases can also happen when the user presses the backspace while holding down the ALT\n // key.\n const isPartialMultiCharEdit =\n editLength > 1 && !isAddition && !isFirstRawValue\n\n // This algorithm doesn't support all cases of multi-character edits, so we just return\n // the current caret position.\n //\n // This works fine for most cases.\n if (isPartialMultiCharEdit) {\n return currentCaretPosition\n }\n\n // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter\n // `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the\n // same as the original `previousConformedValue`. We handle this case differently for caret\n // positioning.\n const possiblyHasRejectedChar =\n isAddition &&\n ((keepCharPositions !== false &&\n previousConformedValue === conformedValue) ||\n conformedValue === placeholder)\n\n let startingSearchIndex = 0\n let trackRightCharacter\n let targetChar\n\n if (possiblyHasRejectedChar) {\n startingSearchIndex = currentCaretPosition - editLength\n } else {\n // At this point in the algorithm, we want to know where the caret is right before the raw input\n // has been conformed, and then see if we can find that same spot in the conformed input.\n //\n // We do that by seeing what character lies immediately before the caret, and then look for that\n // same character in the conformed input and place the caret there.\n\n // First, we need to normalize the inputs so that letter capitalization between raw input and\n // conformed input wouldn't matter.\n const normalizedConformedValue = conformedValue.toLowerCase()\n const normalizedRawValue = rawValue.toLowerCase()\n\n // Then we take all characters that come before where the caret currently is.\n const leftHalfChars = normalizedRawValue\n .substr(0, currentCaretPosition)\n .split(emptyString)\n\n // Now we find all the characters in the left half that exist in the conformed input\n // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.\n const intersection = leftHalfChars.filter(\n (char) => normalizedConformedValue.indexOf(char) !== -1\n )\n\n // The last character in the intersection is the character we want to look for in the conformed\n // value and the one we want to adjust the caret close to\n targetChar = intersection[intersection.length - 1]\n\n // Calculate the number of mask characters in the previous placeholder\n // from the start of the string up to the place where the caret is\n const previousLeftMaskChars = previousPlaceholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Calculate the number of mask characters in the current placeholder\n // from the start of the string up to the place where the caret is\n const leftMaskChars = placeholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Has the number of mask characters up to the caret changed?\n const masklengthChanged = leftMaskChars !== previousLeftMaskChars\n\n // Detect if `targetChar` is a mask character and has moved to the left\n const targetIsMaskMovingLeft =\n previousPlaceholder[intersection.length - 1] !== undefined &&\n placeholder[intersection.length - 2] !== undefined &&\n previousPlaceholder[intersection.length - 1] !== placeholderChar &&\n previousPlaceholder[intersection.length - 1] !==\n placeholder[intersection.length - 1] &&\n previousPlaceholder[intersection.length - 1] ===\n placeholder[intersection.length - 2]\n\n // If deleting and the `targetChar` `is a mask character and `masklengthChanged` is true\n // or the mask is moving to the left, we can't use the selected `targetChar` any longer\n // if we are not at the end of the string.\n // In this case, change tracking strategy and track the character to the right of the caret.\n if (\n !isAddition &&\n (masklengthChanged || targetIsMaskMovingLeft) &&\n previousLeftMaskChars > 0 &&\n placeholder.indexOf(targetChar) > -1 &&\n rawValue[currentCaretPosition] !== undefined\n ) {\n trackRightCharacter = true\n targetChar = rawValue[currentCaretPosition]\n }\n\n // It is possible that `targetChar` will appear multiple times in the conformed value.\n // We need to know not to select a character that looks like our target character from the placeholder or\n // the piped characters, so we inspect the piped characters and the placeholder to see if they contain\n // characters that match our target character.\n\n // If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for\n // our `targetChar`, we don't select a piped char by mistake\n const pipedChars = indexesOfPipedChars.map(\n (index) => normalizedConformedValue[index]\n )\n\n // We need to know how many times the `targetChar` occurs in the piped characters.\n const countTargetCharInPipedChars = pipedChars.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know how many times it occurs in the intersection\n const countTargetCharInIntersection = intersection.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know if the placeholder contains characters that look like\n // our `targetChar`, so we don't select one of those by mistake.\n const countTargetCharInPlaceholder = placeholder\n .substr(0, placeholder.indexOf(placeholderChar))\n .split(emptyString)\n .filter(\n (char, index) =>\n // Check if `char` is the same as our `targetChar`, so we account for it\n char === targetChar &&\n // but also make sure that both the `rawValue` and placeholder don't have the same character at the same\n // index because if they are equal, that means we are already counting those characters in\n // `countTargetCharInIntersection`\n rawValue[index] !== char\n ).length\n\n // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking\n // for is:\n const requiredNumberOfMatches =\n countTargetCharInPlaceholder +\n countTargetCharInIntersection +\n countTargetCharInPipedChars +\n // The character to the right of the caret isn't included in `intersection`\n // so add one if we are tracking the character to the right\n (trackRightCharacter ? 1 : 0)\n\n // Now we start looking for the location of the `targetChar`.\n // We keep looping forward and store the index in every iteration. Once we have encountered\n // enough occurrences of the target character, we break out of the loop\n // If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.\n let numberOfEncounteredMatches = 0\n for (let i = 0; i < conformedValueLength; i++) {\n const conformedValueChar = normalizedConformedValue[i]\n\n startingSearchIndex = i + 1\n\n if (conformedValueChar === targetChar) {\n numberOfEncounteredMatches++\n }\n\n if (numberOfEncounteredMatches >= requiredNumberOfMatches) {\n break\n }\n }\n }\n\n // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,\n // most cases would be handled. However, we want to fast forward or rewind the caret to the\n // closest placeholder character if it happens to be in a non-editable spot. That's what the next\n // logic is for.\n\n // In case of addition, we fast forward.\n if (isAddition) {\n // We want to remember the last placeholder character encountered so that if the mask\n // contains more characters after the last placeholder character, we don't forward the caret\n // that far to the right. Instead, we stop it at the last encountered placeholder character.\n let lastPlaceholderChar = startingSearchIndex\n\n for (let i = startingSearchIndex; i <= placeholderLength; i++) {\n if (placeholder[i] === placeholderChar) {\n lastPlaceholderChar = i\n }\n\n if (\n // If we're adding, we can position the caret at the next placeholder character.\n placeholder[i] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the end of the placeholder. We cannot move any further. Let's put the caret there.\n i === placeholderLength\n ) {\n return lastPlaceholderChar\n }\n }\n } else {\n // In case of deletion, we rewind.\n if (trackRightCharacter) {\n // Searching for the character that was to the right of the caret\n // We start at `startingSearchIndex` - 1 because it includes one character extra to the right\n for (let i = startingSearchIndex - 1; i >= 0; i--) {\n // If tracking the character to the right of the cursor, we move to the left until\n // we found the character and then place the caret right before it\n\n if (\n // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just\n // to the right of the caret\n conformedValue[i] === targetChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n } else {\n // Searching for the first placeholder or caret trap to the left\n\n for (let i = startingSearchIndex; i >= 0; i--) {\n // If we're deleting, we stop the caret right before the placeholder character.\n // For example, for mask `(111) 11`, current conformed input `(456) 86`. If user\n // modifies input to `(456 86`. That is, they deleted the `)`, we place the caret\n // right after the first `6`\n\n if (\n // If we're deleting, we can position the caret right before the placeholder character\n placeholder[i - 1] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,MAAMA,YAAY,GAAG,EAAE;AACvB,MAAMC,WAAW,GAAG,EAAE;AAEtB,eAAe,SAASC,mBAAmBA,CAAAC,IAAA,EAWxC;EAAA,IAXyC;IAC1CC,sBAAsB,GAAGH,WAAW;IACpCI,mBAAmB,GAAGJ,WAAW;IACjCK,oBAAoB,GAAG,CAAC;IACxBC,cAAc;IACdC,QAAQ;IACRC,eAAe;IACfC,WAAW;IACXC,mBAAmB,GAAGX,YAAY;IAClCY,gBAAgB,GAAGZ,YAAY;IAC/Ba,iBAAiB,GAAG;EACtB,CAAC,GAAAV,IAAA;EACC,IAAIG,oBAAoB,KAAK,CAAC,IAAI,CAACE,QAAQ,CAACM,MAAM,EAAE;IAClD,OAAO,CAAC;EACV;EAGA,MAAMC,cAAc,GAAGP,QAAQ,CAACM,MAAM;EACtC,MAAME,4BAA4B,GAAGZ,sBAAsB,CAACU,MAAM;EAClE,MAAMG,iBAAiB,GAAGP,WAAW,CAACI,MAAM;EAC5C,MAAMI,oBAAoB,GAAGX,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CAACwC,CAAC,CAAC,KAAKzC,eAAe,IAElCG,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAElCA,CAAC,KAAKjC,iBAAiB,EACvB;QACA,OAAOmC,mBAAmB;MAC5B;IACF;EACF,CAAC,MAAM;IAEL,IAAI3B,mBAAmB,EAAE;MAGvB,KAAK,IAAIyB,CAAC,GAAG1B,mBAAmB,GAAG,CAAC,EAAE0B,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAIjD,IAGE3C,cAAc,CAAC2C,CAAC,CAAC,KAAKxB,UAAU,IAEhCd,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF,CAAC,MAAM;MAGL,KAAK,IAAIA,CAAC,GAAG1B,mBAAmB,EAAE0B,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAM7C,IAEExC,WAAW,CAACwC,CAAC,GAAG,CAAC,CAAC,KAAKzC,eAAe,IAEtCG,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"adjustCaretPosition.js","names":["defaultArray","emptyString","adjustCaretPosition","_ref","previousConformedValue","previousPlaceholder","currentCaretPosition","conformedValue","rawValue","placeholderChar","placeholder","indexesOfPipedChars","caretTrapIndexes","keepCharPositions","length","rawValueLength","previousConformedValueLength","placeholderLength","conformedValueLength","editLength","isAddition","isFirstRawValue","isPartialMultiCharEdit","possiblyHasRejectedChar","startingSearchIndex","trackRightCharacter","targetChar","normalizedConformedValue","toLowerCase","normalizedRawValue","leftHalfChars","substr","split","intersection","filter","char","indexOf","previousLeftMaskChars","leftMaskChars","maskLengthChanged","targetIsMaskMovingLeft","undefined","pipedChars","map","index","countTargetCharInPipedChars","countTargetCharInIntersection","countTargetCharInPlaceholder","requiredNumberOfMatches","numberOfEncounteredMatches","i","conformedValueChar","lastPlaceholderChar"],"sources":["../../../../../src/components/input-masked/text-mask/adjustCaretPosition.js"],"sourcesContent":["const defaultArray = []\nconst emptyString = ''\n\nexport default function adjustCaretPosition({\n previousConformedValue = emptyString,\n previousPlaceholder = emptyString,\n currentCaretPosition = 0,\n conformedValue,\n rawValue,\n placeholderChar,\n placeholder,\n indexesOfPipedChars = defaultArray,\n caretTrapIndexes = defaultArray,\n keepCharPositions = false,\n}) {\n if (currentCaretPosition === 0 || !rawValue.length) {\n return 0\n }\n\n // Store lengths for faster performance?\n const rawValueLength = rawValue.length\n const previousConformedValueLength = previousConformedValue.length\n const placeholderLength = placeholder.length\n const conformedValueLength = conformedValue.length\n\n // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,\n // we know the user in this instance pasted two characters\n const editLength = rawValueLength - previousConformedValueLength\n\n // If the edit length is positive, that means the user is adding characters, not deleting.\n const isAddition = editLength > 0\n\n // This is the first raw value the user entered that needs to be conformed to mask\n const isFirstRawValue = previousConformedValueLength === 0\n\n // A partial multi-character edit happens when the user makes a partial selection in their\n // input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by\n // selecting the first 3 digits and pressing backspace.\n //\n // Such cases can also happen when the user presses the backspace while holding down the ALT\n // key.\n const isPartialMultiCharEdit =\n editLength > 1 && !isAddition && !isFirstRawValue\n\n // This algorithm doesn't support all cases of multi-character edits, so we just return\n // the current caret position.\n //\n // This works fine for most cases.\n if (isPartialMultiCharEdit) {\n return currentCaretPosition\n }\n\n // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter\n // `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the\n // same as the original `previousConformedValue`. We handle this case differently for caret\n // positioning.\n const possiblyHasRejectedChar =\n isAddition &&\n ((keepCharPositions !== false &&\n previousConformedValue === conformedValue) ||\n conformedValue === placeholder)\n\n let startingSearchIndex = 0\n let trackRightCharacter\n let targetChar\n\n if (possiblyHasRejectedChar) {\n startingSearchIndex = currentCaretPosition - editLength\n } else {\n // At this point in the algorithm, we want to know where the caret is right before the raw input\n // has been conformed, and then see if we can find that same spot in the conformed input.\n //\n // We do that by seeing what character lies immediately before the caret, and then look for that\n // same character in the conformed input and place the caret there.\n\n // First, we need to normalize the inputs so that letter capitalization between raw input and\n // conformed input wouldn't matter.\n const normalizedConformedValue = conformedValue.toLowerCase()\n const normalizedRawValue = rawValue.toLowerCase()\n\n // Then we take all characters that come before where the caret currently is.\n const leftHalfChars = normalizedRawValue\n .substr(0, currentCaretPosition)\n .split(emptyString)\n\n // Now we find all the characters in the left half that exist in the conformed input\n // This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.\n const intersection = leftHalfChars.filter(\n (char) => normalizedConformedValue.indexOf(char) !== -1\n )\n\n // The last character in the intersection is the character we want to look for in the conformed\n // value and the one we want to adjust the caret close to\n targetChar = intersection[intersection.length - 1]\n\n // Calculate the number of mask characters in the previous placeholder\n // from the start of the string up to the place where the caret is\n const previousLeftMaskChars = previousPlaceholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Calculate the number of mask characters in the current placeholder\n // from the start of the string up to the place where the caret is\n const leftMaskChars = placeholder\n .substr(0, intersection.length)\n .split(emptyString)\n .filter((char) => char !== placeholderChar).length\n\n // Has the number of mask characters up to the caret changed?\n const maskLengthChanged = leftMaskChars !== previousLeftMaskChars\n\n // Detect if `targetChar` is a mask character and has moved to the left\n const targetIsMaskMovingLeft =\n previousPlaceholder[intersection.length - 1] !== undefined &&\n placeholder[intersection.length - 2] !== undefined &&\n previousPlaceholder[intersection.length - 1] !== placeholderChar &&\n previousPlaceholder[intersection.length - 1] !==\n placeholder[intersection.length - 1] &&\n previousPlaceholder[intersection.length - 1] ===\n placeholder[intersection.length - 2]\n\n // If deleting and the `targetChar` `is a mask character and `maskLengthChanged` is true\n // or the mask is moving to the left, we can't use the selected `targetChar` any longer\n // if we are not at the end of the string.\n // In this case, change tracking strategy and track the character to the right of the caret.\n if (\n !isAddition &&\n (maskLengthChanged || targetIsMaskMovingLeft) &&\n previousLeftMaskChars > 0 &&\n placeholder.indexOf(targetChar) > -1 &&\n rawValue[currentCaretPosition] !== undefined\n ) {\n trackRightCharacter = true\n targetChar = rawValue[currentCaretPosition]\n }\n\n // It is possible that `targetChar` will appear multiple times in the conformed value.\n // We need to know not to select a character that looks like our target character from the placeholder or\n // the piped characters, so we inspect the piped characters and the placeholder to see if they contain\n // characters that match our target character.\n\n // If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for\n // our `targetChar`, we don't select a piped char by mistake\n const pipedChars = indexesOfPipedChars.map(\n (index) => normalizedConformedValue[index]\n )\n\n // We need to know how many times the `targetChar` occurs in the piped characters.\n const countTargetCharInPipedChars = pipedChars.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know how many times it occurs in the intersection\n const countTargetCharInIntersection = intersection.filter(\n (char) => char === targetChar\n ).length\n\n // We need to know if the placeholder contains characters that look like\n // our `targetChar`, so we don't select one of those by mistake.\n const countTargetCharInPlaceholder = placeholder\n .substr(0, placeholder.indexOf(placeholderChar))\n .split(emptyString)\n .filter(\n (char, index) =>\n // Check if `char` is the same as our `targetChar`, so we account for it\n char === targetChar &&\n // but also make sure that both the `rawValue` and placeholder don't have the same character at the same\n // index because if they are equal, that means we are already counting those characters in\n // `countTargetCharInIntersection`\n rawValue[index] !== char\n ).length\n\n // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking\n // for is:\n const requiredNumberOfMatches =\n countTargetCharInPlaceholder +\n countTargetCharInIntersection +\n countTargetCharInPipedChars +\n // The character to the right of the caret isn't included in `intersection`\n // so add one if we are tracking the character to the right\n (trackRightCharacter ? 1 : 0)\n\n // Now we start looking for the location of the `targetChar`.\n // We keep looping forward and store the index in every iteration. Once we have encountered\n // enough occurrences of the target character, we break out of the loop\n // If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.\n let numberOfEncounteredMatches = 0\n for (let i = 0; i < conformedValueLength; i++) {\n const conformedValueChar = normalizedConformedValue[i]\n\n startingSearchIndex = i + 1\n\n if (conformedValueChar === targetChar) {\n numberOfEncounteredMatches++\n }\n\n if (numberOfEncounteredMatches >= requiredNumberOfMatches) {\n break\n }\n }\n }\n\n // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,\n // most cases would be handled. However, we want to fast forward or rewind the caret to the\n // closest placeholder character if it happens to be in a non-editable spot. That's what the next\n // logic is for.\n\n // In case of addition, we fast forward.\n if (isAddition) {\n // We want to remember the last placeholder character encountered so that if the mask\n // contains more characters after the last placeholder character, we don't forward the caret\n // that far to the right. Instead, we stop it at the last encountered placeholder character.\n let lastPlaceholderChar = startingSearchIndex\n\n for (let i = startingSearchIndex; i <= placeholderLength; i++) {\n if (placeholder[i] === placeholderChar) {\n lastPlaceholderChar = i\n }\n\n if (\n // If we're adding, we can position the caret at the next placeholder character.\n placeholder[i] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the end of the placeholder. We cannot move any further. Let's put the caret there.\n i === placeholderLength\n ) {\n return lastPlaceholderChar\n }\n }\n } else {\n // In case of deletion, we rewind.\n if (trackRightCharacter) {\n // Searching for the character that was to the right of the caret\n // We start at `startingSearchIndex` - 1 because it includes one character extra to the right\n for (let i = startingSearchIndex - 1; i >= 0; i--) {\n // If tracking the character to the right of the cursor, we move to the left until\n // we found the character and then place the caret right before it\n\n if (\n // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just\n // to the right of the caret\n conformedValue[i] === targetChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n } else {\n // Searching for the first placeholder or caret trap to the left\n\n for (let i = startingSearchIndex; i >= 0; i--) {\n // If we're deleting, we stop the caret right before the placeholder character.\n // For example, for mask `(111) 11`, current conformed input `(456) 86`. If user\n // modifies input to `(456 86`. That is, they deleted the `)`, we place the caret\n // right after the first `6`\n\n if (\n // If we're deleting, we can position the caret right before the placeholder character\n placeholder[i - 1] === placeholderChar ||\n // If a caret trap was set by a mask function, we need to stop at the trap.\n caretTrapIndexes.indexOf(i) !== -1 ||\n // This is the beginning of the placeholder. We cannot move any further.\n // Let's put the caret there.\n i === 0\n ) {\n return i\n }\n }\n }\n }\n}\n"],"mappings":"AAAA,MAAMA,YAAY,GAAG,EAAE;AACvB,MAAMC,WAAW,GAAG,EAAE;AAEtB,eAAe,SAASC,mBAAmBA,CAAAC,IAAA,EAWxC;EAAA,IAXyC;IAC1CC,sBAAsB,GAAGH,WAAW;IACpCI,mBAAmB,GAAGJ,WAAW;IACjCK,oBAAoB,GAAG,CAAC;IACxBC,cAAc;IACdC,QAAQ;IACRC,eAAe;IACfC,WAAW;IACXC,mBAAmB,GAAGX,YAAY;IAClCY,gBAAgB,GAAGZ,YAAY;IAC/Ba,iBAAiB,GAAG;EACtB,CAAC,GAAAV,IAAA;EACC,IAAIG,oBAAoB,KAAK,CAAC,IAAI,CAACE,QAAQ,CAACM,MAAM,EAAE;IAClD,OAAO,CAAC;EACV;EAGA,MAAMC,cAAc,GAAGP,QAAQ,CAACM,MAAM;EACtC,MAAME,4BAA4B,GAAGZ,sBAAsB,CAACU,MAAM;EAClE,MAAMG,iBAAiB,GAAGP,WAAW,CAACI,MAAM;EAC5C,MAAMI,oBAAoB,GAAGX,cAAc,CAACO,MAAM;EAIlD,MAAMK,UAAU,GAAGJ,cAAc,GAAGC,4BAA4B;EAGhE,MAAMI,UAAU,GAAGD,UAAU,GAAG,CAAC;EAGjC,MAAME,eAAe,GAAGL,4BAA4B,KAAK,CAAC;EAQ1D,MAAMM,sBAAsB,GAC1BH,UAAU,GAAG,CAAC,IAAI,CAACC,UAAU,IAAI,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CAAC,GAAG1B,mBAAmB,GAAG,CAAC,EAAE0B,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAIjD,IAGE3C,cAAc,CAAC2C,CAAC,CAAC,KAAKxB,UAAU,IAEhCd,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF,CAAC,MAAM;MAGL,KAAK,IAAIA,CAAC,GAAG1B,mBAAmB,EAAE0B,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;QAM7C,IAEExC,WAAW,CAACwC,CAAC,GAAG,CAAC,CAAC,KAAKzC,eAAe,IAEtCG,gBAAgB,CAACwB,OAAO,CAACc,CAAC,CAAC,KAAK,CAAC,CAAC,IAGlCA,CAAC,KAAK,CAAC,EACP;UACA,OAAOA,CAAC;QACV;MACF;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -150,7 +150,8 @@ export default function TooltipContainer(props) {
|
|
|
150
150
|
};
|
|
151
151
|
if (stylesFromPosition[position]) {
|
|
152
152
|
stylesFromPosition[position]();
|
|
153
|
-
}
|
|
153
|
+
}
|
|
154
|
+
if (stylesFromArrow[arrow]) {
|
|
154
155
|
stylesFromArrow[arrow]();
|
|
155
156
|
}
|
|
156
157
|
const rightOffset = parseFloat(String(style.left)) + elementWidth - window.innerWidth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TooltipContainer.js","names":["React","isTrue","getOffsetLeft","getOffsetTop","classnames","TooltipContainer","props","internalId","active","attributes","arrow","position","align","hideDelay","fixedPosition","noAnimation","skipPortal","useHover","children","targetElement","target","style","setStyle","useState","hover","setHover","isActive","wasActive","makeActive","renewStyles","forceRerender","getBodySize","elementRef","useRef","offset","debounceTimeout","resizeObserver","document","width","height","body","getBoundingClientRect","clearTimers","clearTimeout","current","useLayoutEffect","addPositionObserver","ResizeObserver","setTimeout","observe","e","removePositionObserver","_resizeObserver$curre","disconnect","offsetLeft","offsetTop","element","window","alignOffset","elementWidth","offsetWidth","elementHeight","offsetHeight","rect","targetBodySize","scrollY","undefined","pageYOffset","scrollX","pageXOffset","top","useMouseWhen","mousePos","left","widthBased","_objectSpread","topHorizontal","leftVertical","stylesFromPosition","right","bottom","stylesFromArrow","rightOffset","parseFloat","String","innerWidth","handleMouseEnter","handleMouseLeave","handlePropagation","stopPropagation","createElement","_extends","role","ref","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onTouchStart","className","id"],"sources":["../../../../src/components/tooltip/TooltipContainer.tsx"],"sourcesContent":["/**\n * Web Tooltip Component\n *\n */\n\nimport React from 'react'\nimport { isTrue } from '../../shared/component-helper'\nimport { getOffsetLeft, getOffsetTop } from '../../shared/helpers'\nimport classnames from 'classnames'\nimport { TooltipProps } from './types'\n\ntype TooltipContainerProps = {\n targetElement: HTMLElement\n style?: React.CSSProperties\n useHover?: boolean\n internalId?: string\n attributes?: Record<string, unknown> & { style: React.CSSProperties }\n}\n\nexport default function TooltipContainer(\n props: TooltipProps & TooltipContainerProps\n) {\n const {\n internalId,\n active,\n attributes,\n arrow,\n position,\n align,\n hideDelay,\n fixedPosition,\n noAnimation,\n skipPortal,\n useHover,\n children,\n targetElement: target,\n } = props\n\n const [style, setStyle] = React.useState(null)\n const [hover, setHover] = React.useState(false)\n const isActive = isTrue(active) || hover\n const [wasActive, makeActive] = React.useState(false)\n const [renewStyles, forceRerender] = React.useState(getBodySize)\n\n const elementRef = React.useRef<HTMLSpanElement>(null)\n const offset = React.useRef(16)\n const debounceTimeout = React.useRef<NodeJS.Timeout>()\n const resizeObserver = React.useRef<ResizeObserver>(null)\n\n function getBodySize() {\n if (!isActive || typeof document === 'undefined') {\n return 0 // stop here\n }\n\n const { width, height } = document.body.getBoundingClientRect()\n\n return width + height\n }\n\n const clearTimers = () => {\n clearTimeout(debounceTimeout.current)\n }\n\n React.useLayoutEffect(() => {\n const addPositionObserver = () => {\n if (resizeObserver.current || typeof document === 'undefined') {\n return // stop here\n }\n\n try {\n resizeObserver.current = new ResizeObserver(() => {\n clearTimers()\n debounceTimeout.current = setTimeout(\n () => forceRerender(getBodySize()),\n 100\n )\n })\n\n resizeObserver.current.observe(document.body)\n } catch (e) {\n //\n }\n }\n const removePositionObserver = () => {\n clearTimers()\n resizeObserver.current?.disconnect()\n }\n\n if (isActive) {\n makeActive(true)\n addPositionObserver()\n } else {\n removePositionObserver()\n }\n\n return removePositionObserver\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isActive])\n\n const offsetLeft = React.useRef(0)\n const offsetTop = React.useRef(0)\n\n React.useLayoutEffect(() => {\n if (!isActive) {\n /**\n * This \"resets\" the position between elements,\n * when not active. Else it will always first show on the older position.\n */\n if (wasActive) {\n clearTimeout(debounceTimeout.current)\n debounceTimeout.current = setTimeout(\n () => setStyle(null),\n hideDelay\n )\n }\n return // stop here\n }\n\n const element = elementRef?.current\n\n if (\n typeof window === 'undefined' ||\n !element ||\n !target?.getBoundingClientRect\n ) {\n return // stop here\n }\n\n let alignOffset = 0\n\n const elementWidth = element.offsetWidth\n const elementHeight = element.offsetHeight\n const rect = target.getBoundingClientRect()\n const targetBodySize = {\n width: target.offsetWidth,\n height: target.offsetHeight,\n }\n\n // fix for svg\n if (!target.offsetHeight) {\n targetBodySize.width = rect.width\n targetBodySize.height = rect.height\n }\n\n if (skipPortal && (!offsetLeft.current || !offsetTop.current)) {\n offsetLeft.current = getOffsetLeft(element) - offset.current\n offsetTop.current = getOffsetTop(element) - offset.current\n }\n\n const scrollY =\n window.scrollY !== undefined ? window.scrollY : window.pageYOffset\n const scrollX =\n window.scrollX !== undefined ? window.scrollX : window.pageXOffset\n const top =\n (isTrue(fixedPosition) ? 0 : scrollY) + rect.top - offsetTop.current\n\n // Use Mouse position when target is too wide\n const useMouseWhen = targetBodySize.width > 400\n const mousePos =\n getOffsetLeft(target) +\n rect.left / 2 +\n (element ? element.offsetWidth : 0)\n const widthBased = scrollX + rect.left\n const left =\n (useMouseWhen && mousePos < targetBodySize.width\n ? mousePos\n : widthBased) - offsetLeft.current\n\n const style = { ...props.style }\n\n if (align === 'left') {\n alignOffset = -targetBodySize.width / 2\n } else if (align === 'right') {\n alignOffset = targetBodySize.width / 2\n }\n\n const topHorizontal =\n top + targetBodySize.height / 2 - elementHeight / 2\n const leftVertical =\n left - elementWidth / 2 + targetBodySize.width / 2 + alignOffset\n\n const stylesFromPosition = {\n left: () => {\n style.top = topHorizontal\n style.left = left - elementWidth - offset.current\n },\n right: () => {\n style.top = topHorizontal\n style.left = left + targetBodySize.width + offset.current\n },\n top: () => {\n style.left = leftVertical\n style.top = top - elementHeight - offset.current\n },\n bottom: () => {\n style.left = leftVertical\n style.top = top + targetBodySize.height + offset.current\n },\n }\n\n const stylesFromArrow = {\n left: () => {\n style.left =\n left + targetBodySize.width / 2 - offset.current + alignOffset\n },\n right: () => {\n style.left =\n left -\n elementWidth +\n targetBodySize.width / 2 +\n offset.current +\n alignOffset\n },\n top: () => {\n style.top = top + targetBodySize.height / 2 - offset.current\n },\n bottom: () => {\n style.top =\n top + targetBodySize.height / 2 - elementHeight + offset.current\n },\n }\n\n if (stylesFromPosition[position]) {\n stylesFromPosition[position]()\n } else if (stylesFromArrow[arrow]) {\n stylesFromArrow[arrow]()\n }\n\n const rightOffset =\n parseFloat(String(style.left)) + elementWidth - window.innerWidth\n if (rightOffset > 0) {\n style.left = window.innerWidth - elementWidth\n }\n\n if (parseFloat(String(style.left)) < 0) {\n style.left = 0\n }\n if (parseFloat(String(style.top)) < 0) {\n style.top = 0\n }\n\n setStyle(style)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [active, arrow, position, children, renewStyles])\n\n const handleMouseEnter = () => {\n if (isTrue(active) && useHover !== false) {\n setHover(true)\n }\n }\n\n const handleMouseLeave = () => {\n if (useHover !== false) {\n setHover(false)\n }\n }\n\n /**\n * By stopping propagation, we allow the user to select text when Tooltip is used in the Slider component\n */\n const handlePropagation = (e: React.SyntheticEvent) =>\n e.stopPropagation()\n\n return (\n <span\n role=\"tooltip\"\n aria-hidden={target ? true : undefined} // make sure SR does not find it in the DOM, because we use \"aria-describedby\" for that\n ref={elementRef}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onMouseMove={handlePropagation}\n onMouseDown={handlePropagation}\n onTouchStart={handlePropagation}\n {...attributes}\n className={classnames(\n attributes?.className,\n isTrue(noAnimation) && 'dnb-tooltip--no-animation',\n isTrue(fixedPosition) && 'dnb-tooltip--fixed',\n isActive && 'dnb-tooltip--active',\n !isActive && wasActive && 'dnb-tooltip--hide'\n )}\n style={{ ...style, ...attributes.style }}\n >\n {arrow && (\n <span\n className={classnames(\n 'dnb-tooltip__arrow',\n `dnb-tooltip__arrow__arrow--${arrow}`,\n `dnb-tooltip__arrow__position--${position}`\n )}\n />\n )}\n\n <span id={internalId} className=\"dnb-tooltip__content\">\n {children}\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;AAKA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,aAAa,EAAEC,YAAY,QAAQ,sBAAsB;AAClE,OAAOC,UAAU,MAAM,YAAY;AAWnC,eAAe,SAASC,gBAAgBA,CACtCC,KAA2C,EAC3C;EACA,MAAM;IACJC,UAAU;IACVC,MAAM;IACNC,UAAU;IACVC,KAAK;IACLC,QAAQ;IACRC,KAAK;IACLC,SAAS;IACTC,aAAa;IACbC,WAAW;IACXC,UAAU;IACVC,QAAQ;IACRC,QAAQ;IACRC,aAAa,EAAEC;EACjB,CAAC,GAAGd,KAAK;EAET,MAAM,CAACe,KAAK,EAAEC,QAAQ,CAAC,GAAGtB,KAAK,CAACuB,QAAQ,CAAC,IAAI,CAAC;EAC9C,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGzB,KAAK,CAACuB,QAAQ,CAAC,KAAK,CAAC;EAC/C,MAAMG,QAAQ,GAAGzB,MAAM,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C1B,MAAM,CAACc,WAAW,CAAC,IAAI,2BAA2B,EAClDd,MAAM,CAACa,aAAa,CAAC,IAAI,oBAG3B,CAAE;IACFO,KAAK,EAAAsD,aAAA,CAAAA,aAAA,KAAOtD,KAAK,GAAKZ,UAAU,CAACY,KAAK;EAAG,IAExCX,KAAK,IACJV,KAAA,CAAA0F,aAAA;IACES,SAAS,mDAEuBzF,KAAK,kCACFC,QAAQ;EACzC,CACH,CACF,EAEDX,KAAA,CAAA0F,aAAA;IAAMU,EAAE,EAAE7F,UAAW;IAAC4F,SAAS,EAAC;EAAsB,GACnDjF,QACG,CACF,CAAC;AAEX","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"TooltipContainer.js","names":["React","isTrue","getOffsetLeft","getOffsetTop","classnames","TooltipContainer","props","internalId","active","attributes","arrow","position","align","hideDelay","fixedPosition","noAnimation","skipPortal","useHover","children","targetElement","target","style","setStyle","useState","hover","setHover","isActive","wasActive","makeActive","renewStyles","forceRerender","getBodySize","elementRef","useRef","offset","debounceTimeout","resizeObserver","document","width","height","body","getBoundingClientRect","clearTimers","clearTimeout","current","useLayoutEffect","addPositionObserver","ResizeObserver","setTimeout","observe","e","removePositionObserver","_resizeObserver$curre","disconnect","offsetLeft","offsetTop","element","window","alignOffset","elementWidth","offsetWidth","elementHeight","offsetHeight","rect","targetBodySize","scrollY","undefined","pageYOffset","scrollX","pageXOffset","top","useMouseWhen","mousePos","left","widthBased","_objectSpread","topHorizontal","leftVertical","stylesFromPosition","right","bottom","stylesFromArrow","rightOffset","parseFloat","String","innerWidth","handleMouseEnter","handleMouseLeave","handlePropagation","stopPropagation","createElement","_extends","role","ref","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onTouchStart","className","id"],"sources":["../../../../src/components/tooltip/TooltipContainer.tsx"],"sourcesContent":["/**\n * Web Tooltip Component\n *\n */\n\nimport React from 'react'\nimport { isTrue } from '../../shared/component-helper'\nimport { getOffsetLeft, getOffsetTop } from '../../shared/helpers'\nimport classnames from 'classnames'\nimport { TooltipProps } from './types'\n\ntype TooltipContainerProps = {\n targetElement: HTMLElement\n style?: React.CSSProperties\n useHover?: boolean\n internalId?: string\n attributes?: Record<string, unknown> & { style: React.CSSProperties }\n}\n\nexport default function TooltipContainer(\n props: TooltipProps & TooltipContainerProps\n) {\n const {\n internalId,\n active,\n attributes,\n arrow,\n position,\n align,\n hideDelay,\n fixedPosition,\n noAnimation,\n skipPortal,\n useHover,\n children,\n targetElement: target,\n } = props\n\n const [style, setStyle] = React.useState(null)\n const [hover, setHover] = React.useState(false)\n const isActive = isTrue(active) || hover\n const [wasActive, makeActive] = React.useState(false)\n const [renewStyles, forceRerender] = React.useState(getBodySize)\n\n const elementRef = React.useRef<HTMLSpanElement>(null)\n const offset = React.useRef(16)\n const debounceTimeout = React.useRef<NodeJS.Timeout>()\n const resizeObserver = React.useRef<ResizeObserver>(null)\n\n function getBodySize() {\n if (!isActive || typeof document === 'undefined') {\n return 0 // stop here\n }\n\n const { width, height } = document.body.getBoundingClientRect()\n\n return width + height\n }\n\n const clearTimers = () => {\n clearTimeout(debounceTimeout.current)\n }\n\n React.useLayoutEffect(() => {\n const addPositionObserver = () => {\n if (resizeObserver.current || typeof document === 'undefined') {\n return // stop here\n }\n\n try {\n resizeObserver.current = new ResizeObserver(() => {\n clearTimers()\n debounceTimeout.current = setTimeout(\n () => forceRerender(getBodySize()),\n 100\n )\n })\n\n resizeObserver.current.observe(document.body)\n } catch (e) {\n //\n }\n }\n const removePositionObserver = () => {\n clearTimers()\n resizeObserver.current?.disconnect()\n }\n\n if (isActive) {\n makeActive(true)\n addPositionObserver()\n } else {\n removePositionObserver()\n }\n\n return removePositionObserver\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isActive])\n\n const offsetLeft = React.useRef(0)\n const offsetTop = React.useRef(0)\n\n React.useLayoutEffect(() => {\n if (!isActive) {\n /**\n * This \"resets\" the position between elements,\n * when not active. Else it will always first show on the older position.\n */\n if (wasActive) {\n clearTimeout(debounceTimeout.current)\n debounceTimeout.current = setTimeout(\n () => setStyle(null),\n hideDelay\n )\n }\n return // stop here\n }\n\n const element = elementRef?.current\n\n if (\n typeof window === 'undefined' ||\n !element ||\n !target?.getBoundingClientRect\n ) {\n return // stop here\n }\n\n let alignOffset = 0\n\n const elementWidth = element.offsetWidth\n const elementHeight = element.offsetHeight\n const rect = target.getBoundingClientRect()\n const targetBodySize = {\n width: target.offsetWidth,\n height: target.offsetHeight,\n }\n\n // fix for svg\n if (!target.offsetHeight) {\n targetBodySize.width = rect.width\n targetBodySize.height = rect.height\n }\n\n if (skipPortal && (!offsetLeft.current || !offsetTop.current)) {\n offsetLeft.current = getOffsetLeft(element) - offset.current\n offsetTop.current = getOffsetTop(element) - offset.current\n }\n\n const scrollY =\n window.scrollY !== undefined ? window.scrollY : window.pageYOffset\n const scrollX =\n window.scrollX !== undefined ? window.scrollX : window.pageXOffset\n const top =\n (isTrue(fixedPosition) ? 0 : scrollY) + rect.top - offsetTop.current\n\n // Use Mouse position when target is too wide\n const useMouseWhen = targetBodySize.width > 400\n const mousePos =\n getOffsetLeft(target) +\n rect.left / 2 +\n (element ? element.offsetWidth : 0)\n const widthBased = scrollX + rect.left\n const left =\n (useMouseWhen && mousePos < targetBodySize.width\n ? mousePos\n : widthBased) - offsetLeft.current\n\n const style = { ...props.style }\n\n if (align === 'left') {\n alignOffset = -targetBodySize.width / 2\n } else if (align === 'right') {\n alignOffset = targetBodySize.width / 2\n }\n\n const topHorizontal =\n top + targetBodySize.height / 2 - elementHeight / 2\n const leftVertical =\n left - elementWidth / 2 + targetBodySize.width / 2 + alignOffset\n\n const stylesFromPosition = {\n left: () => {\n style.top = topHorizontal\n style.left = left - elementWidth - offset.current\n },\n right: () => {\n style.top = topHorizontal\n style.left = left + targetBodySize.width + offset.current\n },\n top: () => {\n style.left = leftVertical\n style.top = top - elementHeight - offset.current\n },\n bottom: () => {\n style.left = leftVertical\n style.top = top + targetBodySize.height + offset.current\n },\n }\n\n const stylesFromArrow = {\n left: () => {\n style.left =\n left + targetBodySize.width / 2 - offset.current + alignOffset\n },\n right: () => {\n style.left =\n left -\n elementWidth +\n targetBodySize.width / 2 +\n offset.current +\n alignOffset\n },\n top: () => {\n style.top = top + targetBodySize.height / 2 - offset.current\n },\n bottom: () => {\n style.top =\n top + targetBodySize.height / 2 - elementHeight + offset.current\n },\n }\n\n if (stylesFromPosition[position]) {\n stylesFromPosition[position]()\n }\n if (stylesFromArrow[arrow]) {\n stylesFromArrow[arrow]()\n }\n\n const rightOffset =\n parseFloat(String(style.left)) + elementWidth - window.innerWidth\n if (rightOffset > 0) {\n style.left = window.innerWidth - elementWidth\n }\n\n if (parseFloat(String(style.left)) < 0) {\n style.left = 0\n }\n if (parseFloat(String(style.top)) < 0) {\n style.top = 0\n }\n\n setStyle(style)\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [active, arrow, position, children, renewStyles])\n\n const handleMouseEnter = () => {\n if (isTrue(active) && useHover !== false) {\n setHover(true)\n }\n }\n\n const handleMouseLeave = () => {\n if (useHover !== false) {\n setHover(false)\n }\n }\n\n /**\n * By stopping propagation, we allow the user to select text when Tooltip is used in the Slider component\n */\n const handlePropagation = (e: React.SyntheticEvent) =>\n e.stopPropagation()\n\n return (\n <span\n role=\"tooltip\"\n aria-hidden={target ? true : undefined} // make sure SR does not find it in the DOM, because we use \"aria-describedby\" for that\n ref={elementRef}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onMouseMove={handlePropagation}\n onMouseDown={handlePropagation}\n onTouchStart={handlePropagation}\n {...attributes}\n className={classnames(\n attributes?.className,\n isTrue(noAnimation) && 'dnb-tooltip--no-animation',\n isTrue(fixedPosition) && 'dnb-tooltip--fixed',\n isActive && 'dnb-tooltip--active',\n !isActive && wasActive && 'dnb-tooltip--hide'\n )}\n style={{ ...style, ...attributes.style }}\n >\n {arrow && (\n <span\n className={classnames(\n 'dnb-tooltip__arrow',\n `dnb-tooltip__arrow__arrow--${arrow}`,\n `dnb-tooltip__arrow__position--${position}`\n )}\n />\n )}\n\n <span id={internalId} className=\"dnb-tooltip__content\">\n {children}\n </span>\n </span>\n )\n}\n"],"mappings":";;;;;AAKA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,aAAa,EAAEC,YAAY,QAAQ,sBAAsB;AAClE,OAAOC,UAAU,MAAM,YAAY;AAWnC,eAAe,SAASC,gBAAgBA,CACtCC,KAA2C,EAC3C;EACA,MAAM;IACJC,UAAU;IACVC,MAAM;IACNC,UAAU;IACVC,KAAK;IACLC,QAAQ;IACRC,KAAK;IACLC,SAAS;IACTC,aAAa;IACbC,WAAW;IACXC,UAAU;IACVC,QAAQ;IACRC,QAAQ;IACRC,aAAa,EAAEC;EACjB,CAAC,GAAGd,KAAK;EAET,MAAM,CAACe,KAAK,EAAEC,QAAQ,CAAC,GAAGtB,KAAK,CAACuB,QAAQ,CAAC,IAAI,CAAC;EAC9C,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGzB,KAAK,CAACuB,QAAQ,CAAC,KAAK,CAAC;EAC/C,MAAMG,QAAQ,GAAGzB,MAAM,CAACO,MAAM,CAAC,IAAIgB,KAAK;EACxC,MAAM,CAACG,SAAS,EAAEC,UAAU,CAAC,GAAG5B,KAAK,CAACuB,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACM,WAAW,EAAEC,aAAa,CAAC,GAAG9B,KAAK,CAACuB,QAAQ,CAACQ,WAAW,CAAC;EAEhE,MAAMC,UAAU,GAAGhC,KAAK,CAACiC,MAAM,CAAkB,IAAI,CAAC;EACtD,MAAMC,MAAM,GAAGlC,KAAK,CAACiC,MAAM,CAAC,EAAE,CAAC;EAC/B,MAAME,eAAe,GAAGnC,KAAK,CAACiC,MAAM,CAAiB,CAAC;EACtD,MAAMG,cAAc,GAAGpC,KAAK,CAACiC,MAAM,CAAiB,IAAI,CAAC;EAEzD,SAASF,WAAWA,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
|
7
|
-
type DatePickerFooterEvent = React.MouseEvent<HTMLButtonElement> &
|
|
6
|
+
import { DatePickerDates } from './hooks/useDates';
|
|
7
|
+
type DatePickerFooterEvent = React.MouseEvent<HTMLButtonElement> & DatePickerDates & {
|
|
8
8
|
event: React.MouseEvent<HTMLButtonElement>;
|
|
9
9
|
};
|
|
10
10
|
export type DatePickerFooterProps = Omit<React.HTMLProps<HTMLElement>, 'onSubmit' | 'onCancel' | 'onReset'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePickerFooter.js","names":["React","useContext","useCallback","Button","DatePickerContext","convertStringToDate","useTranslation","DatePickerFooter","isRange","submitButtonText","cancelButtonText","resetButtonText","onSubmit","onCancel","onReset","updateDates","previousDateProps","props","contextProps","showResetButton","showCancelButton","showSubmitButton","dateFormat","submitButtonTextTranslation","cancelButtonTextTranslation","resetButtonTextTranslation","DatePicker","onSubmitHandler","args","onCancelHandler","event","persist","startDate","date","endDate","dates","_objectSpread","onResetHandler","undefined","_Fragment","createElement","Fragment","className","text","onClick","_span","icon","icon_position","variant","right","_span2","_span3"],"sources":["../../../../src/components/date-picker/DatePickerFooter.tsx"],"sourcesContent":["/**\n * Web DatePicker Component\n *\n */\n\nimport React, { useContext, useCallback } from 'react'\nimport Button from '../button/Button'\nimport DatePickerContext from './DatePickerContext'\nimport { convertStringToDate } from './DatePickerCalc'\nimport { useTranslation } from '../../shared'\nimport {
|
|
1
|
+
{"version":3,"file":"DatePickerFooter.js","names":["React","useContext","useCallback","Button","DatePickerContext","convertStringToDate","useTranslation","DatePickerFooter","isRange","submitButtonText","cancelButtonText","resetButtonText","onSubmit","onCancel","onReset","updateDates","previousDateProps","props","contextProps","showResetButton","showCancelButton","showSubmitButton","dateFormat","submitButtonTextTranslation","cancelButtonTextTranslation","resetButtonTextTranslation","DatePicker","onSubmitHandler","args","onCancelHandler","event","persist","startDate","date","endDate","dates","_objectSpread","onResetHandler","undefined","_Fragment","createElement","Fragment","className","text","onClick","_span","icon","icon_position","variant","right","_span2","_span3"],"sources":["../../../../src/components/date-picker/DatePickerFooter.tsx"],"sourcesContent":["/**\n * Web DatePicker Component\n *\n */\n\nimport React, { useContext, useCallback } from 'react'\nimport Button from '../button/Button'\nimport DatePickerContext from './DatePickerContext'\nimport { convertStringToDate } from './DatePickerCalc'\nimport { useTranslation } from '../../shared'\nimport { DatePickerDates } from './hooks/useDates'\n\ntype DatePickerFooterEvent = React.MouseEvent<HTMLButtonElement> &\n DatePickerDates & {\n event: React.MouseEvent<HTMLButtonElement>\n }\n\nexport type DatePickerFooterProps = Omit<\n React.HTMLProps<HTMLElement>,\n 'onSubmit' | 'onCancel' | 'onReset'\n> & {\n isRange: boolean\n onSubmit?: (event: DatePickerFooterEvent) => void\n onCancel?: (event: DatePickerFooterEvent) => void\n onReset?: (event: DatePickerFooterEvent) => void\n submitButtonText?: string\n cancelButtonText?: string\n resetButtonText?: string\n}\n\nfunction DatePickerFooter({\n isRange,\n submitButtonText,\n cancelButtonText,\n resetButtonText,\n onSubmit,\n onCancel,\n onReset,\n}: DatePickerFooterProps) {\n const {\n updateDates,\n previousDateProps,\n props: contextProps,\n } = useContext(DatePickerContext)\n\n const {\n showResetButton,\n showCancelButton,\n showSubmitButton,\n dateFormat,\n } = contextProps\n\n const {\n submitButtonText: submitButtonTextTranslation,\n cancelButtonText: cancelButtonTextTranslation,\n resetButtonText: resetButtonTextTranslation,\n } = useTranslation().DatePicker\n\n const onSubmitHandler = useCallback(\n (args: DatePickerFooterEvent) => {\n onSubmit?.(args)\n },\n [onSubmit]\n )\n\n const onCancelHandler = useCallback(\n (args: DatePickerFooterEvent) => {\n if (args && args.event) {\n args.event.persist()\n }\n\n const startDate = previousDateProps.startDate\n ? convertStringToDate(previousDateProps.startDate, {\n dateFormat,\n })\n : previousDateProps.date\n ? convertStringToDate(previousDateProps.date, {\n dateFormat,\n })\n : null\n\n const endDate = previousDateProps.endDate\n ? convertStringToDate(previousDateProps.endDate, {\n dateFormat,\n })\n : startDate\n\n updateDates(\n {\n startDate,\n endDate,\n },\n (dates) => {\n onCancel?.({ ...args, ...dates })\n }\n )\n },\n [dateFormat, updateDates, previousDateProps, onCancel]\n )\n\n const onResetHandler = useCallback(\n (args: DatePickerFooterEvent) => {\n if (args && args.event) {\n args.event.persist()\n }\n\n updateDates(\n {\n date: undefined,\n startDate: undefined,\n endDate: undefined,\n },\n (dates) => {\n onReset?.({ ...args, ...dates })\n }\n )\n },\n [updateDates, onReset]\n )\n\n if (\n !isRange &&\n !showSubmitButton &&\n !showCancelButton &&\n !showResetButton\n ) {\n return <></>\n }\n\n return (\n <div className=\"dnb-date-picker__footer\">\n {((isRange || showSubmitButton) && (\n <Button\n text={submitButtonText || submitButtonTextTranslation}\n onClick={onSubmitHandler}\n data-testid=\"submit\"\n />\n )) || <span />}\n\n <span>\n {(showResetButton && (\n <Button\n text={resetButtonText || resetButtonTextTranslation}\n icon=\"reset\"\n icon_position=\"left\"\n variant=\"tertiary\"\n onClick={onResetHandler}\n data-testid=\"reset\"\n right=\"0.5rem\"\n />\n )) || <span />}\n\n {((isRange || showCancelButton) && (\n <Button\n text={cancelButtonText || cancelButtonTextTranslation}\n icon=\"close\"\n icon_position=\"left\"\n variant=\"tertiary\"\n onClick={onCancelHandler}\n data-testid=\"cancel\"\n right=\"0.5rem\"\n />\n )) || <span />}\n </span>\n </div>\n )\n}\n\nexport default DatePickerFooter\n"],"mappings":";;;;;;AAKA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,QAAQ,OAAO;AACtD,OAAOC,MAAM,MAAM,kBAAkB;AACrC,OAAOC,iBAAiB,MAAM,qBAAqB;AACnD,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,cAAc,QAAQ,cAAc;AAqB7C,SAASC,gBAAgBA,CAAC;EACxBC,OAAO;EACPC,gBAAgB;EAChBC,gBAAgB;EAChBC,eAAe;EACfC,QAAQ;EACRC,QAAQ;EACRC;AACqB,CAAC,EAAE;EACxB,M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,OAAO,EAAC,UAAU;IAClBJ,OAAO,EAAEP,cAAe;IACxB,eAAY,OAAO;IACnBY,KAAK,EAAC;EAAQ,CACf,CACF,IAAAC,MAAA,KAAAA,MAAA,GAAKlD,KAAA,CAAAwC,aAAA,aAAO,CAAC,GAEZ,CAAChC,OAAO,IAAIY,gBAAgB,KAC5BpB,KAAA,CAAAwC,aAAA,CAACrC,MAAM;IACLwC,IAAI,EAAEjC,gBAAgB,IAAIc,2BAA4B;IACtDsB,IAAI,EAAC,OAAO;IACZC,aAAa,EAAC,MAAM;IACpBC,OAAO,EAAC,UAAU;IAClBJ,OAAO,EAAEf,eAAgB;IACzB,eAAY,QAAQ;IACpBoB,KAAK,EAAC;EAAQ,CACf,CACF,IAAAE,MAAA,KAAAA,MAAA,GAAKnD,KAAA,CAAAwC,aAAA,aAAO,CAAC,CACV,CACH,CAAC;AAEV;AAEA,eAAejC,gBAAgB","ignoreList":[]}
|
|
@@ -22,6 +22,7 @@ import { convertStringToDate } from './DatePickerCalc';
|
|
|
22
22
|
import DatePickerContext from './DatePickerContext';
|
|
23
23
|
import { useTranslation } from '../../shared';
|
|
24
24
|
import usePartialDates from './hooks/usePartialDates';
|
|
25
|
+
import useInputDates from './hooks/useInputDates';
|
|
25
26
|
const defaultProps = {
|
|
26
27
|
maskOrder: 'dd/mm/yyyy',
|
|
27
28
|
maskPlaceholder: 'dd/mm/åååå',
|
|
@@ -70,12 +71,6 @@ function DatePickerInput(externalProps) {
|
|
|
70
71
|
updateDates,
|
|
71
72
|
callOnChangeHandler,
|
|
72
73
|
getReturnObject,
|
|
73
|
-
__startDay,
|
|
74
|
-
__startMonth,
|
|
75
|
-
__startYear,
|
|
76
|
-
__endDay,
|
|
77
|
-
__endMonth,
|
|
78
|
-
__endYear,
|
|
79
74
|
startDate,
|
|
80
75
|
endDate,
|
|
81
76
|
props: {
|
|
@@ -84,20 +79,19 @@ function DatePickerInput(externalProps) {
|
|
|
84
79
|
correctInvalidDate
|
|
85
80
|
}
|
|
86
81
|
} = useContext(DatePickerContext);
|
|
82
|
+
const {
|
|
83
|
+
inputDates,
|
|
84
|
+
updateInputDates
|
|
85
|
+
} = useInputDates({
|
|
86
|
+
startDate,
|
|
87
|
+
endDate
|
|
88
|
+
});
|
|
87
89
|
const translation = useTranslation().DatePicker;
|
|
88
90
|
const hasHadValidDate = isValid(startDate) || isValid(endDate);
|
|
89
91
|
const modeDate = useMemo(() => ({
|
|
90
92
|
startDate,
|
|
91
93
|
endDate
|
|
92
94
|
}), [startDate, endDate]);
|
|
93
|
-
const inputDates = useMemo(() => ({
|
|
94
|
-
__startDay,
|
|
95
|
-
__startMonth,
|
|
96
|
-
__startYear,
|
|
97
|
-
__endDay,
|
|
98
|
-
__endMonth,
|
|
99
|
-
__endYear
|
|
100
|
-
}), [__startDay, __startMonth, __startYear, __endDay, __endMonth, __endYear]);
|
|
101
95
|
const inputRefs = useRef({
|
|
102
96
|
startDayRef: {
|
|
103
97
|
current: undefined
|
|
@@ -231,7 +225,7 @@ function DatePickerInput(externalProps) {
|
|
|
231
225
|
event
|
|
232
226
|
}) => {
|
|
233
227
|
const getDates = () => ['start', 'end'].reduce((acc, mode) => {
|
|
234
|
-
acc[`${mode}Date`] = [dateRefs.current[`${mode}Year`] || inputDates[
|
|
228
|
+
acc[`${mode}Date`] = [dateRefs.current[`${mode}Year`] || inputDates[`${mode}Year`] || 'yyyy', dateRefs.current[`${mode}Month`] || inputDates[`${mode}Month`] || 'mm', dateRefs.current[`${mode}Day`] || inputDates[`${mode}Day`] || 'dd'].join('-');
|
|
235
229
|
return acc;
|
|
236
230
|
}, {
|
|
237
231
|
startDate: undefined,
|
|
@@ -301,8 +295,10 @@ function DatePickerInput(externalProps) {
|
|
|
301
295
|
});
|
|
302
296
|
} else {
|
|
303
297
|
updateDates({
|
|
304
|
-
[`${mode}Date`]: null
|
|
305
|
-
|
|
298
|
+
[`${mode}Date`]: null
|
|
299
|
+
});
|
|
300
|
+
updateInputDates({
|
|
301
|
+
[`${mode}${type}`]: value
|
|
306
302
|
});
|
|
307
303
|
invalidDatesRef.current = _objectSpread(_objectSpread({}, invalidDatesRef.current), mode === 'start' ? {
|
|
308
304
|
invalidStartDate: dateString
|
|
@@ -317,7 +313,7 @@ function DatePickerInput(externalProps) {
|
|
|
317
313
|
callOnType({
|
|
318
314
|
event
|
|
319
315
|
});
|
|
320
|
-
}, [updateDates, callOnChange, callOnChangeAsInvalid, callOnType, modeDate, dateRefs, temporaryDates]);
|
|
316
|
+
}, [updateDates, callOnChange, callOnChangeAsInvalid, callOnType, modeDate, dateRefs, temporaryDates, updateInputDates]);
|
|
321
317
|
const dateSetters = useMemo(() => ({
|
|
322
318
|
set_startDay: event => {
|
|
323
319
|
setDate(event, 'start', 'Day');
|
|
@@ -464,7 +460,7 @@ function DatePickerInput(externalProps) {
|
|
|
464
460
|
mask: [/[0-9]/, /[0-9]/],
|
|
465
461
|
inputRef: inputRefs.current[`${mode}DayRef`],
|
|
466
462
|
onChange: dateSetters[`set_${mode}Day`],
|
|
467
|
-
value: inputDates[
|
|
463
|
+
value: inputDates[`${mode}Day`] || '',
|
|
468
464
|
"aria-labelledby": `${id}-${mode}-day-label`
|
|
469
465
|
})), React.createElement("label", {
|
|
470
466
|
key: 'dl' + i,
|
|
@@ -484,7 +480,7 @@ function DatePickerInput(externalProps) {
|
|
|
484
480
|
mask: [/[0-9]/, /[0-9]/],
|
|
485
481
|
inputRef: inputRefs.current[`${mode}MonthRef`],
|
|
486
482
|
onChange: dateSetters[`set_${mode}Month`],
|
|
487
|
-
value: inputDates[
|
|
483
|
+
value: inputDates[`${mode}Month`] || '',
|
|
488
484
|
"aria-labelledby": `${id}-${mode}-month-label`
|
|
489
485
|
})), React.createElement("label", {
|
|
490
486
|
key: 'ml' + i,
|
|
@@ -504,7 +500,7 @@ function DatePickerInput(externalProps) {
|
|
|
504
500
|
mask: [/[0-9]/, /[0-9]/, /[0-9]/, /[0-9]/],
|
|
505
501
|
inputRef: inputRefs.current[`${mode}YearRef`],
|
|
506
502
|
onChange: dateSetters[`set_${mode}Year`],
|
|
507
|
-
value: inputDates[
|
|
503
|
+
value: inputDates[`${mode}Year`] || '',
|
|
508
504
|
"aria-labelledby": `${id}-${mode}-year-label`
|
|
509
505
|
})), React.createElement("label", {
|
|
510
506
|
key: 'yl' + i,
|
|
@@ -609,7 +605,7 @@ function InputElement(_ref) {
|
|
|
609
605
|
function syncDateRefs(dateRefs, inputDates) {
|
|
610
606
|
for (const date in dateRefs.current) {
|
|
611
607
|
const dateRefValue = dateRefs.current[date];
|
|
612
|
-
const inputDateValue = inputDates[
|
|
608
|
+
const inputDateValue = inputDates[date];
|
|
613
609
|
if (dateRefValue !== inputDateValue) {
|
|
614
610
|
dateRefs.current[date] = inputDateValue;
|
|
615
611
|
}
|