-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING CHANGE] feat(Popover): mv to stable (#6129)
🎉 Теперь экспортируется как стабильный компонент. ```diff <Popover - action="hover" + trigger="hover" - offsetDistance={0} + offsetByMainAxis={0} - offsetSkidding={0} + offsetByCrossAxis={0} - shownDelay={0} - hideDelay={10} + hoverDelay={[0, 10]} > <div>Target</div> </Popover> ``` - `trigger` – помимо `"click"` и `"hover"`, теперь принимает `"focus"` или комбинацию этих событий. Также можно передать `"manual"`, что сделает компонент полностью контролируемым, в `onShownChange` будет вызываться при нажатии за пределы целевого и всплывающего элементов, по кнопке ESC или при вызове `onClose` из свойства `content`. - `content` теперь принимает [render prop](https://react.dev/reference/react/cloneElement#passing-data-with-a-render-prop). В аргументе функции можно получить метод `onClose`, с помощью которого можно программно закрывать всплывающий элемента. - `onShownChange` – вторым аргументом теперь приходит `reason`, который даёт понять по какой причине показался/скрылся всплывающий элемент. - `hoverDelay` – принимает либо общее число задержки для `trigger="hover"`, либо массив чисел типа `[<показ>, <скрытие>]`. - `autoFocus` – включать ли авто-фокусирование на всплывающий элемент (работает при навигации с клавиатуры). - `noStyling` – убирает стилизацию по умолчанию. - `usePortal` – рендерить ли всплывающий элемент в портале. Вместо `boolean`, можно передать контейнер, куда должен отрендериться всплывающий элемент.
- Loading branch information
Showing
13 changed files
with
687 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { baselineComponent, waitForFloatingPosition } from '../../testing/utils'; | ||
import { Popover, type PopoverProps } from './Popover'; | ||
|
||
describe(Popover, () => { | ||
baselineComponent((props) => ( | ||
<Popover defaultShown {...props}> | ||
<div>Test</div> | ||
</Popover> | ||
)); | ||
|
||
it('should provide zIndex to popover element', async () => { | ||
const result = render( | ||
<Popover | ||
defaultShown | ||
content="Some popover" | ||
aria-describedby="target" | ||
role="tooltip" | ||
data-testid="popover" | ||
zIndex="100500" | ||
> | ||
<div id="target">Target</div> | ||
</Popover>, | ||
); | ||
await waitForFloatingPosition(); | ||
expect(result.getByTestId('popover').parentElement).toHaveStyle('z-index: 100500'); | ||
}); | ||
|
||
it('should injects aria-expanded attr to target element if correct role provided', async () => { | ||
const Fixture = ({ shown }: PopoverProps) => ( | ||
<Popover | ||
shown={shown} | ||
id="menu" | ||
role="menu" | ||
aria-labelledby="target" | ||
content={<div role="menuitem">1</div>} | ||
> | ||
<div id="target" aria-haspopup="true" aria-controls="menu" data-testid="target"> | ||
Target | ||
</div> | ||
</Popover> | ||
); | ||
const result = render(<Fixture shown />); | ||
await waitForFloatingPosition(); | ||
expect(result.getByTestId('target')).toHaveAttribute('aria-expanded', 'true'); | ||
result.rerender(<Fixture shown={false} />); | ||
await waitForFloatingPosition(); | ||
expect(result.getByTestId('target')).toHaveAttribute('aria-expanded', 'false'); | ||
}); | ||
}); |
Oops, something went wrong.