iTwin / iTwinUI

A design system for building beautiful and well-working web interfaces.
https://itwin.github.io/iTwinUI/
MIT License
92 stars 35 forks source link

[Dialog] support uncontrolled mode and `show()`/`close()` methods #1976

Closed mayank99 closed 4 weeks ago

mayank99 commented 4 weeks ago

Changes

This extends the Dialog's ref using useImperativeHandle to add show()/close() methods.

Usage:

const dialog = React.useRef<typeof Dialog.Ref>(null);

<Button onClick={() => dialog.current?.show()}>Open</Button>
<Dialog ref={dialog}>…</Dialog>

Testing

Added unit test, updated stories.

Docs

Added docs.

mayank99 commented 4 weeks ago

Superseded by #1983

The ref solution may feel more "react-y" but introduces difficulties: