Skip to content

Commit 9b2e746

Browse files
committed
[PRAC/cont] Add tooltips for contact "X" btn
Add/local organiz of logic for tooltips (i.e. beyond customTippy.js). Worth noting: - correct hiding of tooltips at sharp/fast deletion of "contact-rows" (without sticking). core: B-3 / JS-BL
1 parent 3f727a5 commit 9b2e746

File tree

1 file changed

+33
-1
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js

1 file changed

+33
-1
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
addBtn.setAttribute('data-bs-target', '#add-btn-modal');
381381
addModalWrap.setAttribute('id', 'add-btn-modal');
382382
addModalWrap.setAttribute('tabindex', '-1');
383-
addModalWrap.setAttribute('aria-hidden', 'true');
383+
// addModalWrap.setAttribute('aria-hidden', 'true');
384384
addModalHeaderXBtn.setAttribute('type', 'button');
385385
addModalHeaderXBtn.setAttribute('data-bs-dismiss', 'modal');
386386
addModalHeaderXBtn.setAttribute('aria-label', 'Close');
@@ -854,6 +854,9 @@
854854
addModalContactDropBtn.blur(); // снятие фокуса с кнопки (после выбора)
855855
}
856856

857+
// вызов/инициализация tooltips для "X" кнопки (для кнопки удаления строки контактов)
858+
initTippy('.modal__add-body-add-x-btn', 'удалить контакт', 'top');
859+
857860
// организация удаления строки контактов
858861
addModalContactXBtn.addEventListener('click', (event) => {
859862
event.stopPropagation(); // исключение непредвиденных событий/поведения
@@ -925,4 +928,33 @@
925928
}
926929
}
927930
}
931+
932+
// ** дополнительная/местная организация логики для tooltips (т.е. помимо customTippy.js)
933+
function initTippy(selector, content, side) {
934+
if (typeof tippy === 'function') {
935+
tippy(selector, {
936+
content: content,
937+
theme: 'main',
938+
delay: [50, 0],
939+
offset: [0, 13],
940+
placement: side,
941+
animation: 'scale', // анимация появления/скрытия (через дополнительный файл/подключение)
942+
trigger: 'mouseenter', // только по наведению мыши (исключение вывода по клику, в другом месте)
943+
944+
onShow(instance) {
945+
setTimeout(() => {
946+
instance.hide(); // автоматическое скрытие (по истечению времени)
947+
}, 1000);
948+
},
949+
950+
// точечная корректировка стилей (для "стрелки" подсказки)
951+
onMount(instance) {
952+
const arrowElement = instance.popper.querySelector('.tippy-arrow');
953+
arrowElement.style.marginBottom = '-1px';
954+
},
955+
});
956+
} else {
957+
console.error('Tippy.js is not loaded!');
958+
}
959+
}
928960
})();

0 commit comments

Comments
 (0)