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

Passing duration to Toast in JavaScript gets ignored #936

Open
3 tasks done
the-pulli opened this issue Dec 29, 2024 · 2 comments
Open
3 tasks done

Passing duration to Toast in JavaScript gets ignored #936

the-pulli opened this issue Dec 29, 2024 · 2 comments

Comments

@the-pulli
Copy link

Flux version

v1.1.2

Livewire version

v3.5.12

What is the problem?

I'm not sure if it's a bug or a feature. The docs state to issue a Toast from JS one can do:

Flux.toast({
    heading: 'Changes saved',
    text: 'Your changes have been saved.',
    variant: 'success',
})

Hence the reason, I wanna also control the duration of the toast, I added:

Flux.toast({
    heading: 'Changes saved',
    text: 'Your changes have been saved.',
    variant: 'success',
    duration: 0,
})

But this will be ignored. Is this intended? Because the PHP variant with passing a duration works fine.

Code snippets

Working as expected:

Flux.toast({
    heading: 'Changes saved',
    text: 'Your changes have been saved.',
    variant: 'success',
})

Instead of being displayed indefenitely, the duration gets ignored:

Flux.toast({
    heading: 'Changes saved',
    text: 'Your changes have been saved.',
    variant: 'success',
    duration: 0,
})

How do you expect it to work?

That the duration flag is passed properly to the Toast component in JS.

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be closed if I haven't met the criteria above.
@jeffchown
Copy link

@the-pulli Looks like the vendor/livewire/flux-pro/js/store.js file needs a line added to forward the duration param, e.g.:

if (options.duration) detail.duration = options.duration

@calebporzio @joshhanley ?

@joshhanley
Copy link
Member

@the-pulli thanks for reporting and thanks @jeffchown for checking! I've submitted a PR with a fix.

One small change to Jeff's suggestion though, we need to check if duration is undefined a 0 is a valid duration, which returns false in the conditional.

if (options.duration !== undefined) detail.duration = options.duration

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

3 participants