Skip to content

Commit 3bc4e6e

Browse files
authored
Fix secondary nav htmx attributes (#820)
* Fix secondary nav htmx attributes * Revert ts
1 parent 6e63c07 commit 3bc4e6e

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/Elastic.Markdown/Helpers/Htmx.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ public static string GetHxSelectOob(bool hasSameTopLevelGroup)
2222
public const string HxPushUrl = "true";
2323
public const string HxIndicator = "#htmx-indicator";
2424

25-
public static string GetHxAttributes(string targetUrl, bool hasSameTopLevelGroup, string? preload = Preload)
25+
public static string GetHxAttributes(
26+
string targetUrl,
27+
bool hasSameTopLevelGroup = false,
28+
string? preload = Preload,
29+
string? hxSwapOob = null,
30+
string? hxSwap = HxSwap,
31+
string? hxPushUrl = HxPushUrl,
32+
string? hxIndicator = HxIndicator
33+
)
2634
{
2735
var attributes = new StringBuilder();
2836
_ = attributes.Append($" hx-get={targetUrl}");
29-
_ = attributes.Append($" hx-select-oob={GetHxSelectOob(hasSameTopLevelGroup)}");
30-
_ = attributes.Append($" hx-swap={HxSwap}");
31-
_ = attributes.Append($" hx-push-url={HxPushUrl}");
32-
_ = attributes.Append($" hx-indicator={HxIndicator}");
37+
_ = attributes.Append($" hx-select-oob={hxSwapOob ?? GetHxSelectOob(hasSameTopLevelGroup)}");
38+
_ = attributes.Append($" hx-swap={hxSwap}");
39+
_ = attributes.Append($" hx-push-url={hxPushUrl}");
40+
_ = attributes.Append($" hx-indicator={hxIndicator}");
3341
_ = attributes.Append($" preload={preload}");
3442
return attributes.ToString();
3543
}

src/Elastic.Markdown/Slices/Layout/_SecondaryNav.cshtml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,33 @@
1818
<li class="text-nowrap hover:text-blue-elastic active:text-blue-elastic-100">
1919
<a
2020
href="@Model.Link("/release-notes")"
21-
@Htmx.GetHxAttributes(Model.Link("/release-notes"), false)>
21+
@Htmx.GetHxAttributes(
22+
targetUrl: Model.Link("/release-notes"),
23+
hxSwapOob: "#main-container"
24+
)
25+
>
2226
Release notes
2327
</a>
2428
</li>
2529
<li class="text-nowrap hover:text-blue-elastic active:text-blue-elastic-100">
2630
<a
2731
href="@Model.Link("/troubleshoot")"
28-
@Htmx.GetHxAttributes(Model.Link("/troubleshoot"), false)>
32+
@Htmx.GetHxAttributes(
33+
targetUrl: Model.Link("/troubleshoot"),
34+
hxSwapOob: "#main-container"
35+
)
36+
>
2937
Troubleshoot
3038
</a>
3139
</li>
3240
<li class="text-nowrap hover:text-blue-elastic active:text-blue-elastic-100">
3341
<a
3442
href="@Model.Link("/reference")"
35-
@Htmx.GetHxAttributes(Model.Link("/reference"), false)>
43+
@Htmx.GetHxAttributes(
44+
Model.Link("/reference"),
45+
hxSwapOob: "#main-container"
46+
)
47+
>
3648
Reference
3749
</a>
3850
</li>

src/Elastic.Markdown/Slices/Layout/_TocTree.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<a
1414
class="hover:underline text-blue-elastic hover:text-blue-elastic-100"
1515
href="@current.Group.Index?.Url"
16-
@Htmx.GetHxAttributes(current.Group.Index?.Url!, false)
16+
@Htmx.GetHxAttributes(current.Group.Index?.Url!)
1717
>
1818
@current.Group.Index?.NavigationTitle
1919
</a>

0 commit comments

Comments
 (0)