Skip to content

Commit

Permalink
feat(@clayui/drop-down): replaces direct use of dom-align with doAlig…
Browse files Browse the repository at this point in the history
…n with RTL support
  • Loading branch information
matuzalemsteles committed Aug 27, 2021
1 parent 372f94d commit a311dca
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions packages/clay-drop-down/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import {ClayPortal, IPortalBaseProps, Keys, observeRect} from '@clayui/shared';
import {
ClayPortal,
IPortalBaseProps,
Keys,
doAlign,
observeRect,
} from '@clayui/shared';
import classNames from 'classnames';
import domAlign from 'dom-align';
import React, {useEffect, useLayoutEffect, useMemo, useRef} from 'react';
import React, {useEffect, useLayoutEffect, useRef} from 'react';

export const Align = {
BottomCenter: 4,
Expand Down Expand Up @@ -200,12 +205,6 @@ const ClayDropDownMenu = React.forwardRef<HTMLDivElement, IProps>(
) => {
const subPortalRef = useRef<HTMLDivElement | null>(null);

const rtl = useMemo(() => {
return (
document.querySelector('html')?.getAttribute('dir') === 'rtl'
);
}, []);

useEffect(() => {
if (closeOnClickOutside) {
const handleClick = (event: MouseEvent) => {
Expand Down Expand Up @@ -268,19 +267,17 @@ const ClayDropDownMenu = React.forwardRef<HTMLDivElement, IProps>(
}

if ((ref as React.RefObject<HTMLElement>).current) {
domAlign(
(ref as React.RefObject<HTMLElement>).current!,
alignElementRef.current,
{
offset: offsetFn(points),
overflow: {
adjustX: autoBestAlign,
adjustY: autoBestAlign,
},
points,
useCssRight: rtl,
}
);
doAlign({
offset: offsetFn(points),
overflow: {
adjustX: autoBestAlign,
adjustY: autoBestAlign,
},
points,
sourceElement: (ref as React.RefObject<HTMLElement>)
.current!,
targetElement: alignElementRef.current,
});
}
}
};
Expand Down

0 comments on commit a311dca

Please sign in to comment.