Skip to content

Commit 06ab885

Browse files
werzlAdam Hewitt
andauthored
Set 'disabled' attribute on RadzenPager links when on the first/last page (#1627)
* Set 'disabled' attribute on RadzenPager buttons * add tests * fix pager test --------- Co-authored-by: Adam Hewitt <ahewitt@glasswall.com>
1 parent b552790 commit 06ab885

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

Radzen.Blazor.Tests/PagerTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,51 @@ public void RadzenPager_Renders_PagerDensityCompact()
109109

110110
Assert.Contains(@$"rz-density-compact", component.Markup);
111111
}
112+
113+
[Fact]
114+
public async void RadzenPager_First_And_Prev_Buttons_Are_Disabled_When_On_The_First_Page()
115+
{
116+
using var ctx = new TestContext();
117+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
118+
ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js");
119+
120+
var component = ctx.RenderComponent<RadzenPager>(parameters => {
121+
parameters.Add<int>(p => p.PageSize, 10);
122+
parameters.Add<int>(p => p.Count, 100);
123+
parameters.Add<bool>(p => p.ShowPagingSummary, true);
124+
});
125+
126+
await component.Instance.GoToPage(0);
127+
component.Render();
128+
129+
var firstPageButton = component.Find("a.rz-pager-first");
130+
Assert.True(firstPageButton.HasAttribute("disabled"));
131+
132+
var prevPageButton = component.Find("a.rz-pager-prev");
133+
Assert.True(prevPageButton.HasAttribute("disabled"));
134+
}
135+
136+
[Fact]
137+
public async void RadzenPager_Last_And_Next_Buttons_Are_Disabled_When_On_The_Last_Page()
138+
{
139+
using var ctx = new TestContext();
140+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
141+
ctx.JSInterop.SetupModule("_content/Radzen.Blazor/Radzen.Blazor.js");
142+
143+
var component = ctx.RenderComponent<RadzenPager>(parameters => {
144+
parameters.Add<int>(p => p.PageSize, 10);
145+
parameters.Add<int>(p => p.Count, 100);
146+
parameters.Add<bool>(p => p.ShowPagingSummary, true);
147+
});
148+
149+
await component.Instance.GoToPage(9);
150+
component.Render();
151+
152+
var lastPageButton = component.Find("a.rz-pager-last");
153+
Assert.True(lastPageButton.HasAttribute("disabled"));
154+
155+
var nextPageButton = component.Find("a.rz-pager-next");
156+
Assert.True(nextPageButton.HasAttribute("disabled"));
157+
}
112158
}
113159
}

Radzen.Blazor/RadzenPager.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
{
99
<span class="rz-pager-summary">@((MarkupString)string.Format(PagingSummaryFormat, CurrentPage + 1, numberOfPages, Count))</span>
1010
}
11-
<a d="@(GetId() + "fp")" class="rz-pager-first rz-pager-element @(skip > 0 ? "": "rz-state-disabled") @(focusedIndex == -2 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => FirstPage())" aria-label="@FirstPageAriaLabel" role="button" title="@FirstPageTitle">
11+
<a d="@(GetId() + "fp")" class="rz-pager-first rz-pager-element @(skip > 0 ? "": "rz-state-disabled") @(focusedIndex == -2 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => FirstPage())" aria-label="@FirstPageAriaLabel" role="button" title="@FirstPageTitle" disabled="@(CurrentPage <= 0)">
1212
<span class="rz-pager-icon rzi rzi-step-backward"></span>
1313
</a>
1414

15-
<a id="@(GetId() + "pp")" class="rz-pager-prev rz-pager-element @(skip > 0 ? "": "rz-state-disabled") @(focusedIndex == -1 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => PrevPage())" aria-label="@PrevPageAriaLabel" role="button" title="@PrevPageTitle">
15+
<a id="@(GetId() + "pp")" class="rz-pager-prev rz-pager-element @(skip > 0 ? "": "rz-state-disabled") @(focusedIndex == -1 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => PrevPage())" aria-label="@PrevPageAriaLabel" role="button" title="@PrevPageTitle" disabled="@(CurrentPage <= 0)">
1616
<span class="rz-pager-icon rzi rzi-caret-left"></span>
1717
@if (PrevPageLabel != null)
1818
{
@@ -27,15 +27,15 @@
2727
}
2828
</span>
2929

30-
<a id="@(GetId() + "np")" class="rz-pager-next rz-pager-element @((CurrentPage != numberOfPages - 1) ? "": "rz-state-disabled") @(focusedIndex == Math.Min(endPage + 1, PageNumbersCount)? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => NextPage())" aria-label="@NextPageAriaLabel" role="button" title="@NextPageTitle">
30+
<a id="@(GetId() + "np")" class="rz-pager-next rz-pager-element @((CurrentPage != numberOfPages - 1) ? "": "rz-state-disabled") @(focusedIndex == Math.Min(endPage + 1, PageNumbersCount)? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => NextPage())" aria-label="@NextPageAriaLabel" role="button" title="@NextPageTitle" disabled="@(CurrentPage >= (numberOfPages - 1))">
3131
@if (NextPageLabel != null)
3232
{
3333
<span class="rz-pager-label">@NextPageLabel</span>
3434
}
3535
<span class="rz-pager-icon rzi rzi-caret-right"></span>
3636
</a>
3737

38-
<a id="@(GetId() + "lp")" class="rz-pager-last rz-pager-element @((CurrentPage != numberOfPages - 1) ? "": "rz-state-disabled") @(focusedIndex == Math.Min(endPage + 1, PageNumbersCount) + 1 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => LastPage())" aria-label="@LastPageAriaLabel" role="button" title="@LastPageTitle">
38+
<a id="@(GetId() + "lp")" class="rz-pager-last rz-pager-element @((CurrentPage != numberOfPages - 1) ? "": "rz-state-disabled") @(focusedIndex == Math.Min(endPage + 1, PageNumbersCount) + 1 ? "rz-state-focused": "")" @onclick:preventDefault="true" @onclick="@(() => LastPage())" aria-label="@LastPageAriaLabel" role="button" title="@LastPageTitle" disabled="@(CurrentPage >= (numberOfPages - 1))">
3939
<span class="rz-pager-icon rzi rzi-step-forward"></span>
4040
</a>
4141

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy