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

fix: add modalId prop for Modal #780

Merged
merged 2 commits into from
May 21, 2023
Merged

Conversation

RyanZhiNie
Copy link
Contributor

@RyanZhiNie RyanZhiNie commented May 20, 2023

Closes #771

πŸ“‘ Description

Add the modalId prop to set the id attribute for the generated modal element.

Status

  • Not Completed
  • Completed

βœ… Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

β„Ή Additional Information

@stackblitz
Copy link

stackblitz bot commented May 20, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link

vercel bot commented May 20, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
flowbite-svelte βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 21, 2023 8:31am
flowbite-svelte-update βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 21, 2023 8:31am

@shinokada
Copy link
Collaborator

It looks good to me.
@jjagielka What do you think?

@shinokada
Copy link
Collaborator

Thank you for the PR.
I modified a bit.

  • use id instead of modalId
  • add outsideclose prop to close a modal by clicking the outside modal
  • dependencies updates
  • workflow update
  • etc.

@jjagielka
Copy link
Contributor

Why did we need that id to be set? Original code has already <Frame rounded shadow {...$$restProps} class={frameClass}> and you were able to set id via $$restProps.

You have now introduce a static id called outsideModalId which is against the framework creation rules.

@shinokada
Copy link
Collaborator

You are right.
I put this issue because It had a hard-coded id.
We could use $$restProps in the first Frame for id.

As for the modal outside click functionality, I have a few reasons for implementing it:

  • We have been receiving constant requests for the outside click function both here and in the Discord channel.
  • It is not enabled by default, giving developers the flexibility to choose whether or not to use it.
  • To close the modal, I added the id attribute with the value id="outerModal". I opted for an id since only one modal is open at a time, but using a class is also a viable option.

I understand your opinion against the outside click. But I would appreciate it if you could provide any suggestions for a better solution for closing a modal by outside click.

@jjagielka
Copy link
Contributor

For the outside close it was as easy as adding one line to onAutoClose handler and no id settings was needed.

const onAutoClose = (e: MouseEvent) => {
    const target: Element = e.target as Element;
    if (autoclose && target?.tagName === 'BUTTON') hide(e); // close on any button click
    if (outsideclose && target === e.currentTarget) hide(e); // close on click outside
  };

@shinokada
Copy link
Collaborator

@jjagielka Thank you for your input. I just updated the Modal component.

@jjagielka
Copy link
Contributor

@shinokada I'm sorry I've noticed a small issue with the solution proposed. That handler is conditionally connected:

on:click={autoclose ? onAutoClose : null}

we need to change it to:

on:click={onAutoClose}

or

on:click={autoclose || outsideclose ? onAutoClose : null}

@shinokada shinokada mentioned this pull request May 25, 2023
8 tasks
@shinokada
Copy link
Collaborator

@jjagielka Done and thanks.

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

Successfully merging this pull request may close these issues.

Modal id is fixed
3 participants