Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLASMA-4108: add zIndex prop in Dropdown, Select, Combobox #1631

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,18 @@ describe('plasma-b2c: Combobox', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<div style={{ width: '300px' }}>
<Combobox id="single" items={items} label="Label" placeholder="Placeholder" zIndex={10000} />
</div>,
);

cy.get('#single').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('flow: single uncontrolled', () => {
cy.viewport(1000, 500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,20 @@ describe('plasma-b2c: Dropdown', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<CypressTestDecoratorWithTypo>
<Dropdown items={items} zIndex={10000}>
<Button text="Список стран" />
</Dropdown>
</CypressTestDecoratorWithTypo>,
);

cy.get('button').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('keyboard interactions', () => {
cy.viewport(1000, 500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,18 @@ describe('plasma-b2c: Select', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<div style={{ width: '300px' }}>
<Select id="single" items={items} label="Label" placeholder="Placeholder" zIndex={10000} />
</div>,
);

cy.get('#single').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('basic logic', () => {
cy.viewport(1000, 500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const comboboxRoot = (Root: RootProps<HTMLInputElement, Omit<ComboboxProp
filter,
closeAfterSelect: outerCloseAfterSelect,
renderValue,
zIndex,
...rest
} = props;

Expand Down Expand Up @@ -453,6 +454,7 @@ export const comboboxRoot = (Root: RootProps<HTMLInputElement, Omit<ComboboxProp
onEnterDisabled // Пропс для отключения обработчика Enter внутри Textfield
/>
)}
zIndex={zIndex}
>
<Root
size={size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CSSProperties, ButtonHTMLAttributes, ChangeEventHandler } from 're
import React from 'react';

import { RequiredProps, LabelProps } from '../../TextField/TextField.types';
import { DropdownProps } from '../../Dropdown/Dropdown.types';

import { FocusedPathState } from './reducers';
import { ItemOption, ItemOptionTransformed } from './ui/Inner/ui/Item/Item.types';
Expand Down Expand Up @@ -163,6 +164,10 @@ type BasicProps<T extends ItemOption = ItemOption> = {
* @default normal
*/
variant?: 'normal' | 'tight';
/**
* CSS-свойство z-index для выпадающего списка.
*/
zIndex?: CSSProperties['zIndex'];
/**
* Значение css overflow для выпадающего меню.
* @example listOverflow="scroll"
Expand Down Expand Up @@ -221,6 +226,7 @@ export type FloatingPopoverProps = {
portal?: ComboboxProps['portal'];
listWidth?: ComboboxProps['listWidth'];
offset?: number;
zIndex?: DropdownProps['zIndex'];
};

export type ItemContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { safeUseId } from '@salutejs/plasma-core';
import type { FloatingPopoverProps } from './Combobox.types';

const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
({ target, children, opened, onToggle, placement, portal, listWidth, offset = 0 }, ref) => {
({ target, children, opened, onToggle, placement, portal, listWidth, offset = 0, zIndex }, ref) => {
const { refs, floatingStyles } = useFloating({
placement,
open: opened,
Expand Down Expand Up @@ -47,7 +47,7 @@ const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
// root - принимает ref контейнера портала.
// id - если есть портал - не используется, если портала нет - подставляется 'wrappedId'.
<FloatingPortal {...getFloatingPortalProps(portal, wrappedId)}>
<div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: 1 }}>
<div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: zIndex || 1000 }}>
{children}
</div>
</FloatingPortal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const dropdownRoot = (Root: RootProps<HTMLDivElement, Omit<DropdownProps,
alwaysOpened = false,
portal,
renderItem,
zIndex,
...rest
},
ref,
Expand Down Expand Up @@ -141,6 +142,7 @@ export const dropdownRoot = (Root: RootProps<HTMLDivElement, Omit<DropdownProps,
: '',
onKeyDown,
})}
zIndex={zIndex}
>
<Root
className={cx(className, classes.dropdownRoot)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export type DropdownProps<T extends DropdownItemOption = DropdownItemOption> = {
* Callback для кастомной настройки айтема в выпадающем списке.
*/
renderItem?: (item: T) => React.ReactNode;
/**
* CSS-свойство z-index для выпадающего списка.
*/
zIndex?: CSSProperties['zIndex'];

/**
* Обработчик клика по item.
Expand Down Expand Up @@ -130,6 +134,7 @@ export type FloatingPopoverProps = {
isInner?: boolean;
portal?: DropdownProps['portal'];
offset?: [number, number];
zIndex?: DropdownProps['zIndex'];
};

export type ItemContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { safeUseId } from '@salutejs/plasma-core';
import { FloatingPopoverProps } from './Dropdown.types';

const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
({ target, children, opened, onToggle, placement, portal, offset = [0, 0], isInner, trigger }, ref) => {
({ target, children, opened, onToggle, placement, portal, offset = [0, 0], isInner, trigger, zIndex }, ref) => {
const { refs, floatingStyles } = useFloating({
placement: placement === 'auto' ? undefined : placement,
open: opened,
Expand Down Expand Up @@ -96,7 +96,7 @@ const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
onMouseLeave={handleFloatingMouseLeave}
style={{
...floatingStyles,
zIndex: 1,
zIndex: zIndex || 1000,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getPlacement, getFallbackPlacements } from './utils';
import type { FloatingPopoverProps } from './Select.types';

const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
({ target, children, opened, onToggle, placement, portal, listWidth, offset = 0 }, ref) => {
({ target, children, opened, onToggle, placement, portal, listWidth, offset = 0, zIndex }, ref) => {
const { refs, floatingStyles } = useFloating({
placement: getPlacement(placement),
open: opened,
Expand Down Expand Up @@ -48,7 +48,7 @@ const FloatingPopover = forwardRef<HTMLDivElement, FloatingPopoverProps>(
// root - принимает ref контейнера портала.
// id - если есть портал - не используется, если портала нет - подставляется 'wrappedId'.
<FloatingPortal {...getFloatingPortalProps(portal, wrappedId)}>
<div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: 1 }}>
<div ref={refs.setFloating} style={{ ...floatingStyles, zIndex: zIndex || 1000 }}>
{children}
</div>
</FloatingPortal>
Expand Down
2 changes: 2 additions & 0 deletions packages/plasma-new-hope/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
isTargetAmount,
beforeList,
afterList,
zIndex,
...rest
} = props;
const transformedItems = useMemo(() => initialItemsTransform(items || []), [items]);
Expand Down Expand Up @@ -329,6 +330,7 @@ export const selectRoot = (Root: RootProps<HTMLButtonElement, Omit<MergedSelectP
requiredProps={requiredProps}
/>
)}
zIndex={zIndex}
>
<Root
view={view}
Expand Down
10 changes: 10 additions & 0 deletions packages/plasma-new-hope/src/components/Select/Select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CSSProperties, ButtonHTMLAttributes, SyntheticEvent } from 'react'
import React from 'react';

import type { RequiredProps, LabelProps } from '../TextField/TextField.types';
import { DropdownProps } from '../Dropdown/Dropdown.types';

import { FocusedPathState } from './reducers';
import {
Expand Down Expand Up @@ -109,6 +110,10 @@ export interface BasicProps<K extends ItemOption> {
* @default normal
*/
variant?: 'normal' | 'tight';
/**
* CSS-свойство z-index для выпадающего списка.
*/
zIndex?: CSSProperties['zIndex'];
/**
* Значение css overflow для выпадающего меню.
* @example listOverflow="scroll"
Expand Down Expand Up @@ -294,6 +299,10 @@ export type MergedSelectProps<T = any, K extends DropdownNode = DropdownNode> =
* @default normal
*/
variant?: 'normal' | 'tight';
/**
* CSS-свойство z-index для выпадающего списка.
*/
zIndex?: CSSProperties['zIndex'];
/**
* Значение css width для выпадающего списка.
* @example width="200px"
Expand Down Expand Up @@ -363,4 +372,5 @@ export type FloatingPopoverProps = {
portal?: MergedSelectProps['portal'];
listWidth?: MergedSelectProps['listWidth'];
offset?: number;
zIndex?: DropdownProps['zIndex'];
};
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ const SingleStory = (args: StorySelectProps) => {
value={value}
onChange={setValue}
contentLeft={args.enableContentLeft ? <IconDone size="s" /> : undefined}
onToggle={(e) => console.log(e)}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/plasma-web/api/plasma-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,18 @@ describe('plasma-web: Combobox', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<div style={{ width: '300px' }}>
<Combobox id="single" items={items} label="Label" placeholder="Placeholder" zIndex={10000} />
</div>,
);

cy.get('#single').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('flow: single uncontrolled', () => {
cy.viewport(1000, 500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,20 @@ describe('plasma-web: Dropdown', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<CypressTestDecoratorWithTypo>
<Dropdown items={items} zIndex={10000}>
<Button text="Список стран" />
</Dropdown>
</CypressTestDecoratorWithTypo>,
);

cy.get('button').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('keyboard interactions', () => {
cy.viewport(1000, 500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,18 @@ describe('plasma-web: Select', () => {
cy.get('[id$="north_america"]').should('have.attr', 'data-name', 'test-data-name');
});

it('prop: zIndex', () => {
mount(
<div style={{ width: '300px' }}>
<Select id="single" items={items} label="Label" placeholder="Placeholder" zIndex={10000} />
</div>,
);

cy.get('#single').realClick();

cy.get('[data-floating-ui-portal] > div').should('have.css', 'z-index', '10000');
});

it('basic logic', () => {
cy.viewport(1000, 500);

Expand Down
1 change: 1 addition & 0 deletions packages/sdds-cs/api/sdds-cs.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/sdds-dfa/api/sdds-dfa.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/sdds-finportal/api/sdds-finportal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/sdds-insol/api/sdds-insol.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/sdds-serv/api/sdds-serv.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ default: PolymorphicClassName;
variant?: "normal" | "tight" | undefined;
portal?: string | React_2.RefObject<HTMLElement> | undefined;
renderItem?: ((item: DropdownItemOption) => React_2.ReactNode) | undefined;
zIndex?: Property.ZIndex | undefined;
onItemClick?: ((item: DropdownItemOption, event: React_2.SyntheticEvent<Element, Event>) => void) | undefined;
listOverflow?: Property.Overflow | undefined;
listHeight?: Property.Height<string | number> | undefined;
Expand Down
Loading