@antscorp/antsomi-ui 2.0.96 → 2.0.97
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.
|
@@ -893,21 +893,30 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
893
893
|
style.type = 'text/css';
|
|
894
894
|
style.appendChild(document.createTextNode(`
|
|
895
895
|
.tagify__tooltip {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
896
|
+
display: none;
|
|
897
|
+
position: fixed;
|
|
898
|
+
background-color: #595959;
|
|
899
|
+
border-radius: 10px;
|
|
900
|
+
color: #ffffff;
|
|
901
|
+
padding: 6px;
|
|
902
|
+
z-index: 10000;
|
|
903
|
+
max-width: 280px;
|
|
904
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
|
903
905
|
}
|
|
906
|
+
|
|
904
907
|
.tagify__tooltip_content {
|
|
905
908
|
width: 100%;
|
|
906
|
-
|
|
909
|
+
max-width: 250px;
|
|
910
|
+
height: auto;
|
|
907
911
|
position: relative;
|
|
908
912
|
transition: 0s;
|
|
909
913
|
font-size: 12px;
|
|
914
|
+
line-height: 16px;
|
|
915
|
+
text-align: center;
|
|
916
|
+
word-wrap: break-word;
|
|
917
|
+
white-space: normal;
|
|
910
918
|
}
|
|
919
|
+
|
|
911
920
|
.tagify__tooltip_content:before {
|
|
912
921
|
content: '';
|
|
913
922
|
position: absolute;
|
|
@@ -933,30 +942,60 @@ const TagifyInput = forwardRef((props, ref) => {
|
|
|
933
942
|
}, []);
|
|
934
943
|
useDeepCompareEffect(() => {
|
|
935
944
|
const showTooltip = (tagElement) => {
|
|
945
|
+
const isTagReadonly = tagifyRef.current?.settings.readonly;
|
|
946
|
+
const tagType = tagElement.getAttribute('type');
|
|
947
|
+
// If tag is readonly and tag type is hint for link, do not show the tooltip
|
|
948
|
+
if (isTagReadonly && tagType === DETECT_LINK)
|
|
949
|
+
return;
|
|
936
950
|
const tagRect = tagElement.getBoundingClientRect();
|
|
937
|
-
const removeTag = tagElement.getAttribute(REMOVED_TAG);
|
|
938
|
-
const noViewTag = tagElement.getAttribute(NO_VIEW_TAG);
|
|
939
|
-
const invalidTag = tagElement.getAttribute(INVALID_TAG);
|
|
940
951
|
const messageTag = tagElement.getAttribute(MESSAGE_TAG);
|
|
941
|
-
const
|
|
952
|
+
const tagText = tagElement.querySelector('.tagify__tag-text');
|
|
953
|
+
// Determine what content to show in tooltip
|
|
954
|
+
let tooltipMessage = '';
|
|
942
955
|
if (messageTag) {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
956
|
+
tooltipMessage = messageTag;
|
|
957
|
+
}
|
|
958
|
+
else if (tagText) {
|
|
959
|
+
tooltipMessage = tagText.textContent || '';
|
|
960
|
+
}
|
|
961
|
+
// Update tooltip content first
|
|
962
|
+
const tooltipContent = document.querySelector('.tagify__tooltip_content');
|
|
963
|
+
if (tooltipContent && tooltipMessage) {
|
|
964
|
+
tooltipContent.innerHTML = tooltipMessage;
|
|
947
965
|
}
|
|
948
966
|
const tooltip = document.querySelector('.tagify__tooltip');
|
|
949
|
-
tooltip
|
|
967
|
+
// Show tooltip temporarily to measure its dimensions after content is set
|
|
968
|
+
tooltip?.setAttribute('style', 'display: block !important; visibility: hidden !important; position: fixed; top: -9999px; left: -9999px;');
|
|
969
|
+
// Get the actual dimensions after content is applied
|
|
950
970
|
const tooltipRect = tooltip?.getBoundingClientRect();
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
971
|
+
const shouldShowTooltip = tooltipRect && tooltipMessage !== '';
|
|
972
|
+
if (shouldShowTooltip) {
|
|
973
|
+
// Calculate dynamic offset based on actual tooltip height plus some padding
|
|
974
|
+
const tooltipHeight = tooltipRect.height;
|
|
975
|
+
const offsetTop = tooltipHeight + 8; // 8px padding between tooltip and tag
|
|
976
|
+
const top = tagRect.y - offsetTop;
|
|
977
|
+
// Handle horizontal positioning
|
|
955
978
|
if (tooltipRect?.width > tagRect.width) {
|
|
956
|
-
|
|
979
|
+
const left = tagRect.x - (tooltipRect.width - tagRect.width) / 2;
|
|
980
|
+
// Ensure tooltip doesn't go off-screen horizontally
|
|
981
|
+
const viewportWidth = window.innerWidth;
|
|
982
|
+
const adjustedLeft = Math.max(0, Math.min(left, viewportWidth - tooltipRect.width));
|
|
983
|
+
tooltip?.setAttribute('style', `visibility: visible !important; display: block !important; top: ${top}px; left: ${adjustedLeft}px; position: fixed;`);
|
|
957
984
|
}
|
|
958
985
|
else {
|
|
959
|
-
|
|
986
|
+
const left = tagRect.x + (tagRect.width - tooltipRect.width) / 2;
|
|
987
|
+
// Ensure tooltip doesn't go off-screen horizontally
|
|
988
|
+
const viewportWidth = window.innerWidth;
|
|
989
|
+
const adjustedLeft = Math.max(0, Math.min(left, viewportWidth - tooltipRect.width));
|
|
990
|
+
tooltip?.setAttribute('style', `visibility: visible !important; display: block !important; top: ${top}px; left: ${adjustedLeft}px; position: fixed;`);
|
|
991
|
+
}
|
|
992
|
+
// Handle case where tooltip would appear above viewport
|
|
993
|
+
if (top < 0) {
|
|
994
|
+
// Position tooltip below the tag instead
|
|
995
|
+
const bottomTop = tagRect.bottom + 10;
|
|
996
|
+
const currentStyle = tooltip?.getAttribute('style') || '';
|
|
997
|
+
const updatedStyle = currentStyle.replace(/top:\s*[^;]+/, `top: ${bottomTop}px`);
|
|
998
|
+
tooltip?.setAttribute('style', updatedStyle);
|
|
960
999
|
}
|
|
961
1000
|
}
|
|
962
1001
|
};
|