Comments (2)
I looked into this because I'm considering using Flowbite for a Blazor/Tailwind project I'm working on and I got it to fix by doing this:
(Ensure npm/tailwind is downloaded and already set up)
- Use libman instead of npm to add Flowbite to your wwwroot folder. I used cdnjs as the provider
- Update
_Host.cshtml
to use the flowbite.min.js file we just added in wwwroot
@page "/"
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@namespace BlazorApp.Pages
<!DOCTYPE html>
<html lang="en">
...
<script src="~/flowbite/flowbite.min.js"></script>
</html>
- Update
tailwind.config.js
to add the new javascript file to the content module:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
// other files...
"./wwwroot/**/*.js"
],
...
}
- Update
Index.razor
to do the following:
- Inject and use the
IJSRuntime
to invoke the flowbite functioninitModals
to initialize the modal. - Include a missing attribute
data-modal-target
to the button that opens the modal. The value should be the id of the modal you want to open.
@page "/"
@inject IJSRuntime JSRuntime;
<!-- Modal toggle -->
<div class="flex justify-center m-5">
<button id="defaultModalButton" data-modal-toggle="defaultModal" data-modal-target="defaultModal" class="block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
Show modal
</button>
</div>
<!-- Main modal -->
...
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
await JSRuntime.InvokeVoidAsync("initModals");
}
}
The result looks like this on my end:
Also make sure to run the npx tailwind command to recreate your css file again
from tailwind-blazor-starter.
Thank for your example. I implement and it work as expected with modal, dropdown, ...
But seem like the datepicker component doesn't work. I'm trying to figure out the issue.
Could you please try to implement it?
from tailwind-blazor-starter.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tailwind-blazor-starter.