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

[Feature Request] Floating components with "hide" technique in order to close them. #457

Open
Angel-Ponce opened this issue Sep 5, 2023 · 0 comments

Comments

@Angel-Ponce
Copy link

Usage example, including component, action, motion, or utility API

For example using the Modal within Popper component

<script>
 import { Modal, Group, Button, Popper } from '@svelteuidev/core';

 let opened = false;
 let mounted = false;
</script>

<Button bind:element={reference} on:click={() => (mounted = !mounted)}>Click here</Button>

<Popper {reference} {mounted}>
 <Button on:click={() => (opened = true)}>Open Modal</Button>
 <Modal {opened} on:close={()=>(opened = false)}>
  <Input  />
 </Modal>
</Popper>

So, in this example the Modal component only works if the Popper component is mounted, otherwise, the Modal will be unmounted automatically.

The solution is easy, put the Modal component out of the Popper component, but, it will generate a bad anatomy in the code:

<script>
 import { Modal, Group, Button, Popper } from '@svelteuidev/core';

 let opened = false;
 let mounted = false;
</script>

<Button bind:element={reference} on:click={() => (mounted = !mounted)}>Click here</Button>

<Popper {reference} {mounted}>
 /* the button trigger is in the popper component */
 <Button on:click={() => (opened = true)}>Open Modal</Button>
</Popper>

/* the modal is out of popper component */
<Modal {opened} on:close={()=>(opened = false)}>
 <Input  />
</Modal>

Possible implementation - describe how the feature can be implemented

If we could decide between "destroy" and "hide" techinque to close the popper this code will have'nt bugs.

<script>
 import { Modal, Group, Button, Popper } from '@svelteuidev/core';

 let opened = false;
 let mounted = false;
</script>

<Button bind:element={reference} on:click={() => (mounted = !mounted)}>Click here</Button>

<Popper {reference} {mounted} destroyOnClose={false}> <------------ destroyOnClose false, use the "hide" technique
 <Button on:click={() => (opened = true)}>Open Modal</Button>
 <Modal {opened} on:close={()=>(opened = false)}>
  <Input  />
 </Modal>
</Popper>

Do you want to contribute this feature and create a pull request

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant