diff --git a/src/BlazorStrap/BlazorStrap.csproj b/src/BlazorStrap/BlazorStrap.csproj
index d2afc627..aa6c1550 100644
--- a/src/BlazorStrap/BlazorStrap.csproj
+++ b/src/BlazorStrap/BlazorStrap.csproj
@@ -13,7 +13,7 @@
https://blazorstrap.io/
https://github.com/chanan/BlazorStrap
BlazorStrap
- 5.2.103-Beta1
+ 5.2.103-Beta1a
6.0
diff --git a/src/BlazorStrap/Service/BlazorStrapInterop.cs b/src/BlazorStrap/Service/BlazorStrapInterop.cs
index d5f0b6e0..0a60aa01 100644
--- a/src/BlazorStrap/Service/BlazorStrapInterop.cs
+++ b/src/BlazorStrap/Service/BlazorStrapInterop.cs
@@ -290,7 +290,6 @@ public async ValueTask ToastTimerAsync(ElementReference? elementReference, int t
if (elementReference is null || module is null) return;
await module.InvokeVoidAsync("toastTimer", cancellationToken ?? CancellationToken.None, elementReference, time, timeRemaining, rendered);
}
- //TODO: Direct Points from old JS
///
/// Triggers Carousel to animate
///
@@ -303,12 +302,9 @@ public async ValueTask ToastTimerAsync(ElementReference? elementReference, int t
public async ValueTask AnimateCarouselAsync(string id, ElementReference? showElementReference, ElementReference? hideElementReference, bool back, bool v4, CancellationToken? cancellationToken = null)
{
var module = await GetModuleAsync();
- if (module is null)
- throw new NullReferenceException("Unable to load module.");
- if (showElementReference == null)
- throw new ArgumentNullException(nameof(showElementReference));
- if (hideElementReference == null)
- throw new ArgumentNullException(nameof(hideElementReference));
+ //If anything is null just return true. Animation will not trigger but the slide will still change.
+ if(module is null || showElementReference is null || hideElementReference is null)
+ return true;
return await module.InvokeAsync("animateCarousel", cancellationToken ?? CancellationToken.None, id, showElementReference, hideElementReference, back, v4, _objectReference);
}
@@ -322,7 +318,8 @@ public async ValueTask AnimateCarouselAsync(string id, ElementReference? s
///
public async ValueTask PreloadModuleAsync(CancellationToken? cancellationToken = null)
{
- _ = await GetModuleAsync() ?? throw new NullReferenceException("Unable to load module.");
+ //This might return null if this method is called be JS interop is ready. Since we are only preloading here we can ignore this.
+ _ = await GetModuleAsync();
}
///
diff --git a/src/BlazorStrap/Shared/Components/Common/BSCarouselBase.cs b/src/BlazorStrap/Shared/Components/Common/BSCarouselBase.cs
index a2aed872..90ec92ec 100644
--- a/src/BlazorStrap/Shared/Components/Common/BSCarouselBase.cs
+++ b/src/BlazorStrap/Shared/Components/Common/BSCarouselBase.cs
@@ -132,25 +132,33 @@ internal async Task GotoChildSlide(BSCarouselItemBase item)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0045:Convert to conditional expression", Justification = "")]
public async Task BackAsync()
{
- if (ClickLocked) return;
- ClickLocked = true;
+ try
+ {
+ if (ClickLocked) return;
+ ClickLocked = true;
- var last = _active;
- _active--;
+ var last = _active;
+ _active--;
- if (_active < 0)
- _active = Children.Count - 1;
- if (last == 0)
- _last = last;
+ if (_active < 0)
+ _active = Children.Count - 1;
+ if (last == 0)
+ _last = last;
- else
- _last = _active + 1;
- await Children[_last].InternalHide();
- await Children[_active].InternalShow();
- await DoAnimations(true);
+ else
+ _last = _active + 1;
+ await Children[_last].InternalHide();
+ await Children[_active].InternalShow();
+ await DoAnimations(true);
- await InvokeAsync(() => { IndicatorsRef?.Refresh(Children.Count, _active); });
- ResetTransitionTimer(Children[_active].Interval);
+ await InvokeAsync(() => { IndicatorsRef?.Refresh(Children.Count, _active); });
+ ResetTransitionTimer(Children[_active].Interval);
+ }
+ catch (Exception e)
+ {
+ // When navigating to a different page, the carousel Children are removed from the DOM, causing an exception this can be ignored.
+ // The timer can tick just as this happens. This is why we need to catch the exception.
+ }
}
///
@@ -160,25 +168,34 @@ public async Task BackAsync()
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0045:Convert to conditional expression", Justification = "")]
public async Task NextAsync()
{
- if (ClickLocked) return;
- ClickLocked = true;
- _active++;
- if (_active > Children.Count - 1)
- _active = 0;
+ try
+ {
+ if (ClickLocked) return;
+ ClickLocked = true;
+ _active++;
+ if (_active > Children.Count - 1)
+ _active = 0;
- if (_active == 0)
- _last = Children.Count - 1;
+ if (_active == 0)
+ _last = Children.Count - 1;
- else
- _last = _active - 1;
- await Children[_last].InternalHide();
- await Children[_active].InternalShow();
+ else
+ _last = _active - 1;
+ await Children[_last].InternalHide();
+ await Children[_active].InternalShow();
- await DoAnimations(false);
+ await DoAnimations(false);
- await InvokeAsync(() => { IndicatorsRef?.Refresh(Children.Count, _active); });
- ResetTransitionTimer(Children[_active].Interval);
+ await InvokeAsync(() => { IndicatorsRef?.Refresh(Children.Count, _active); });
+ if (Children.Count > _active)
+ ResetTransitionTimer(Children[_active].Interval);
+ }
+ catch (Exception e)
+ {
+ // When navigating to a different page, the carousel Children are removed from the DOM, causing an exception this can be ignored.
+ // The timer can tick just as this happens. This is why we need to catch the exception.
+ }
}
protected abstract Task DoAnimations(bool back);