MM-53230 : Remove custom polyfilled 'getClosestParent' with browser 'closest' (#24086)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6d6e589c11
Коммит
e37459cd00
@@ -4,7 +4,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import SuggestionList from 'components/suggestion/suggestion_list';
|
import SuggestionList from 'components/suggestion/suggestion_list';
|
||||||
import {getClosestParent} from 'utils/utils';
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
interface SuggestionItem {}
|
interface SuggestionItem {}
|
||||||
@@ -88,7 +87,7 @@ export default class ModalSuggestionList extends React.PureComponent<Props, Stat
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.container.current) {
|
if (this.container.current) {
|
||||||
const modalBodyContainer = getClosestParent(this.container.current, '.modal-body');
|
const modalBodyContainer = this.container.current.closest('.modal-body');
|
||||||
modalBodyContainer?.addEventListener('scroll', this.onModalScroll);
|
modalBodyContainer?.addEventListener('scroll', this.onModalScroll);
|
||||||
}
|
}
|
||||||
window.addEventListener('resize', this.updateModalBounds);
|
window.addEventListener('resize', this.updateModalBounds);
|
||||||
@@ -96,7 +95,7 @@ export default class ModalSuggestionList extends React.PureComponent<Props, Stat
|
|||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this.container.current) {
|
if (this.container.current) {
|
||||||
const modalBodyContainer = getClosestParent(this.container.current, '.modal-body');
|
const modalBodyContainer = this.container.current.closest('.modal-body');
|
||||||
modalBodyContainer?.removeEventListener('scroll', this.onModalScroll);
|
modalBodyContainer?.removeEventListener('scroll', this.onModalScroll);
|
||||||
}
|
}
|
||||||
window.removeEventListener('resize', this.updateModalBounds);
|
window.removeEventListener('resize', this.updateModalBounds);
|
||||||
@@ -116,7 +115,8 @@ export default class ModalSuggestionList extends React.PureComponent<Props, Stat
|
|||||||
this.updatePosition(newInputBounds);
|
this.updatePosition(newInputBounds);
|
||||||
|
|
||||||
if (this.container.current) {
|
if (this.container.current) {
|
||||||
const modalBodyRect = getClosestParent(this.container.current, '.modal-body')?.getBoundingClientRect();
|
const modalBodyContainer = this.container.current.closest('.modal-body');
|
||||||
|
const modalBodyRect = modalBodyContainer?.getBoundingClientRect();
|
||||||
if (modalBodyRect && ((newInputBounds.bottom < modalBodyRect.top) || (newInputBounds.top > modalBodyRect.bottom))) {
|
if (modalBodyRect && ((newInputBounds.bottom < modalBodyRect.top) || (newInputBounds.top > modalBodyRect.bottom))) {
|
||||||
this.props.onLoseVisibility();
|
this.props.onLoseVisibility();
|
||||||
return;
|
return;
|
||||||
@@ -180,8 +180,8 @@ export default class ModalSuggestionList extends React.PureComponent<Props, Stat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modalContainer = getClosestParent(this.container.current, '.modal-content');
|
const modalBodyContainer = this.container.current.closest('.modal-body');
|
||||||
const modalBounds = modalContainer?.getBoundingClientRect();
|
const modalBounds = modalBodyContainer?.getBoundingClientRect();
|
||||||
|
|
||||||
if (modalBounds) {
|
if (modalBounds) {
|
||||||
if (this.state.modalBounds.top !== modalBounds.top || this.state.modalBounds.bottom !== modalBounds.bottom) {
|
if (this.state.modalBounds.top !== modalBounds.top || this.state.modalBounds.bottom !== modalBounds.bottom) {
|
||||||
|
|||||||
@@ -1571,43 +1571,6 @@ export function setCSRFFromCookie() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get closest parent which match selector
|
|
||||||
*/
|
|
||||||
export function getClosestParent(elem: HTMLElement, selector: string) {
|
|
||||||
// Element.matches() polyfill
|
|
||||||
if (!Element.prototype.matches) {
|
|
||||||
Element.prototype.matches =
|
|
||||||
(Element.prototype as any).matchesSelector ||
|
|
||||||
(Element.prototype as any).mozMatchesSelector ||
|
|
||||||
(Element.prototype as any).msMatchesSelector ||
|
|
||||||
(Element.prototype as any).oMatchesSelector ||
|
|
||||||
(Element.prototype as any).webkitMatchesSelector ||
|
|
||||||
((s) => {
|
|
||||||
// @ts-expect-error // TODO: resolve this typing and see if using function this is necessary
|
|
||||||
const matches = (this.document || this.ownerDocument).querySelectorAll(s);
|
|
||||||
let i = matches.length - 1;
|
|
||||||
|
|
||||||
// @ts-expect-error // TODO: resolve this typing and see if using function this is necessary
|
|
||||||
while (i >= 0 && matches.item(i) !== this) {
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return i > -1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the closest matching element
|
|
||||||
let currentElem = elem;
|
|
||||||
|
|
||||||
// @ts-expect-error // TODO: resolve this typing and see if using function this is necessary
|
|
||||||
for (; currentElem && currentElem !== document; currentElem = currentElem.parentNode) {
|
|
||||||
if (currentElem.matches(selector)) {
|
|
||||||
return currentElem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNextBillingDate() {
|
export function getNextBillingDate() {
|
||||||
const nextBillingDate = moment().add(1, 'months').startOf('month');
|
const nextBillingDate = moment().add(1, 'months').startOf('month');
|
||||||
return nextBillingDate.format('MMM D, YYYY');
|
return nextBillingDate.format('MMM D, YYYY');
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user