JSException after clicking on a link inside SelectedTemplate
See original GitHub issueHow to reproduce:
- Create a blazor server-side project with the template in VS 2019 16.4(+)
- Setup BlazoredTypeahead, like described in your documentation.
- Add a razor page under “Pages”, e.g. “Issue.razor” with the following content:
@page "/issue"
<EditForm Model="Model">
<BlazoredTypeahead
SearchMethod="MySearchAsync"
@bind-Value="Model.Foo"
EnableDropDown="true"
placeholder="Search ..."
id="foo">
<SelectedTemplate Context="item">
<NavLink href="counter">@item</NavLink>
</SelectedTemplate>
<ResultTemplate Context="item">
@item
</ResultTemplate>
</BlazoredTypeahead>
</EditForm>
@code {
private MyModel Model { get; set; } = new MyModel();
private Task<IEnumerable<string>> MySearchAsync(string input)
{
return Task.FromResult(Enumerable.Range(1, 3).Select(i => $"My Entry {i}"));
}
class MyModel
{
public string Foo { get; set; }
}
}
- Edit NavMenu.razor, add a new entry:
<li class="nav-item px-3">
<NavLink class="nav-link" href="issue">
<span class="oi oi-list-rich" aria-hidden="true"></span> Test issue
</NavLink>
</li>
- Start the app, go to the page “Test issue”
- Select an item
- Click on the link which was generated for the current item
- -> Exception in
BlazoredTypeahead`2.HandleClickOnMask
:
Microsoft.JSInterop.JSException: 'element is null
setFocus@https://localhost:44356/_content/Blazored.Typeahead/blazored-typeahead.js:4:9
beginInvokeJSFromDotNet/r<@https://localhost:44356/_framework/blazor.server.js:8:31421
beginInvokeJSFromDotNet@https://localhost:44356/_framework/blazor.server.js:8:31390
C</e.prototype.invokeClientMethod/<@https://localhost:44356/_framework/blazor.server.js:1:19202
C</e.prototype.invokeClientMethod@https://localhost:44356/_framework/blazor.server.js:1:19173
C</e.prototype.processIncomingData@https://localhost:44356/_framework/blazor.server.js:1:17165
e/this.connection.onreceive@https://localhost:44356/_framework/blazor.server.js:1:10276
A</e.prototype.connect/</</</i.onmessage@https://localhost:44356/_framework/blazor.server.js:1:38091
'
Hint:
If you look at the code of HandleClickOnMask
, it waits 250 ms from the click to the javascript interop call. During this waiting time, the html element probably got removed at the browser side.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Storing HREF value after clicking link - javascript
My idea was to store the HREF value from the clicked link, and then use this href value to have the page scroll...
Read more >Clicking Anchor link, it gets appended in URL. How to stop it?
Solved: Hi, I'm using anchor links in page for some purpose within it. But when anchor link is clicked, it gets appended to...
Read more >Back to Basics: Non-Navigating Links for JavaScript Handling
When you're creating <a href> links that are non-navigating and handled via script code or through some JavaScript framework, how exactly do ...
Read more >Creating Anchor Links in Blazor Applications
The problem with anchor links is that when you click on them, the page won't scroll to the element you've specified in the...
Read more >Click link with javascript does not open link.
Hi all. I am having an issue trying to get PAD to click the link which would open a download option but it's...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sven-n Well, that’s handy! 😃 We’ll get this shipped soon.
Thanks for letting us know @trademark18. I’m working on a big update to Blazored Modal that I’m trying to get out this week. Once that is done I’ll get back over to Typeahead and look to ship a new version.