MudChip: Use anchor or button tag instead of div when appropriate#10488
MudChip: Use anchor or button tag instead of div when appropriate#10488danielchalmers merged 23 commits intoMudBlazor:devfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #10488 +/- ##
==========================================
- Coverage 91.58% 91.54% -0.05%
==========================================
Files 426 425 -1
Lines 13278 13319 +41
Branches 2550 2564 +14
==========================================
+ Hits 12161 12193 +32
- Misses 546 551 +5
- Partials 571 575 +4 ☔ View full report in Codecov by Sentry. |
| class="@Classname" | ||
| style="@Style" | ||
| @onclick="this.AsNonRenderingEventHandler<MouseEventArgs>(OnClickAsync)"> | ||
| <MudElement HtmlTag="@GetHtmlTag()" |
There was a problem hiding this comment.
Won't have time to fully check the PR until later today but we recently ran into a problem at work where we wanted to have interactive content within a tags, only to find out that this violates the HTML spec (and we couldn't get events to only propagate to the children, it always triggered the anchor click):
I think we would have to either disable the IsClosable render path when an anchor tag is used, or move the IsClosable render path out of the anchor tag.
There was a problem hiding this comment.
Would it be better if the close button was overlayed on top instead of nested inside?
There was a problem hiding this comment.
The scenario at my work place was to have a clickable card as well as action buttons on the right side of it.
We had essentially this setup:
<ClickableCard> @* translates into an anchor tag *@
<MudGrid>
<SomeVisualComponents />
<SomeActionButtons />
</MudGrid>
</ClickableCard>Since we couldn't get this to work because of the anchor tag issue we are going to do something like this (not yet implemented):
<ClickableCard> @* no anchor tag *@
<CardContent>
<SomeVisualComponents />
</CardContent>
<ActionAreaContent>
<SomeActionButtons />
</ActionAreaContent>
</ClickableCard>The ClickableCard handles hover state/styling, the CardContent is the anchor tag, the ActionAreaContent is the extra area that is not part of the anchor tag. The downside here is that you give up the space taken by the buttons as clickable area.
The alternative would have been to, like you said, overlay the button on top of the clickable area. For us that was too annoying to handle, especially with multiple buttons and potentially other content within that second area.
FYI I just tried with MUI and they don't handle that case either. Their link Chips are also anchor tags, but if you make the chip "deletable" they add an SVG with an onclick handler (so technically not HTML spec violation), but of course when you click on the SVG the anchor tag triggers.
igotinfected
left a comment
There was a problem hiding this comment.
LGTM other than the anchor/interactive children issue!
|
I've disabled the Enter key intercept, OnClick event, and Close button for anchor chips to not interfere with the browser's default behavior. Does anyone agree/disagree? May have to cut my losses and close the PR because I couldn't find another way. |
|
|
Enter key intercept, OnClick event, and Close button are all removed for anchor chips to not interfere with the browser's default behavior. Is this reasonable or should I close the PR? @igotinfected @ScarletKuro @henon @mckaragoz |
|
I think it is reasonable. You agree @igotinfected ? |
|
Yup makes sense to me! |
|
Added to migration guide:
|




Description
The MudChip now renders a semantic anchor tag in place if the
divif anhrefis specified. This improves accessibility, including allowing the user to hover it to see the link it will direct them to, middle click to open in a new tab, or drag to another place.Additionally,
Relwas added (as seen in MudButton).It can now be a true anchor and so no longer acts like a button. Breaking changes:
How Has This Been Tested?
unit, visually
Type of Changes
Checklist
dev).