Contributing Guidelines
Thanks for contributing! ๐
Whether it's fixing bugs, improving docs, or adding features your help is appreciated.
By submitting a pull request, you agree that your contribution is licensed under the project's MIT License (see LICENSE.txt) and may be distributed as part of the project.
๐ Index
- Code of Conduct
- Prerequisites
- Project Structure
- Top-Level Folders
- Getting Started
- CSS
- Coding Guidelines
- Component Guidelines
- Adding a New Component
- Testing
- Branching Strategy
- Pull Requests
- Releasing & Versioning
- Common Mistakes
- Before Large Changes
- Keeping Your Branch Updated
- CI / Checks
- Quick Checklist
๐ Code of Conduct
Be respectful and constructive. See CODE_OF_CONDUCT.md.
โ๏ธ Prerequisites
- .NET 11 SDK (pinned in
global.json), plus the .NET 10 runtime to run the tests against both target frameworks
Project Structure
TwBlazor/
โโโ build/ # Build-time tooling
โ โโโ TwBlazor.BuildTools/ # Generates Generated/CodeExamples.cs before TwBlazor.Docs builds
โ โโโ TwBlazor.Docs.Compiler/ # CodeExample/#region extraction library used by TwBlazor.BuildTools
โ โโโ CodeExampleExtractor.cs
โ โโโ RegionSnippetExtractor.cs
โ โโโ CodeGenerator.cs
โ โโโ Paths.cs
โ โโโ SnippetTextUtils.cs
โโโ docs/ # Documentation site content, hosts, and docfx (API reference) config
โ โโโ templates/ # Custom docfx template
โ โโโ toc.yml
โ โโโ TwBlazor.Docs/ # Documentation content (shared by the Server and WASM hosts)
โ โ โโโ Generated/
โ โ โโโ Layout/
โ โ โโโ Pages/
โ โ โโโ wwwroot/
โ โโโ TwBlazor.Server/ # Server-side host
โ โ โโโ Components/
โ โ โ โโโ Layout/
โ โ โ โโโ Pages/
โ โ โโโ Program.cs
โ โโโ TwBlazor.WASM/ # WASM project
โ โ โโโ Program.cs
โ โโโ TwBlazor.WasmHost/ # WASM host
โ โโโ Pages/
โ โ โโโ _Host.cshtml
โ โโโ Program.cs
โโโ src/ # Published library code
โ โโโ TwBlazor/ # Component library
โ โ โโโ Builders/
โ โ โโโ Components/
โ โ โโโ Configuration/
โ โ โโโ Enums/
โ โ โโโ Extensions/
โ โ โโโ Models/
โ โ โโโ Services/
โ โ โโโ Utilities/
โ โ โโโ wwwroot/
โ โโโ TwBlazor.Theme/ # Theme definitions
โ โโโ Theme.cs
โโโ tests/ # Automated tests
โโโ vitest.config.js # JS unit test config (see TwBlazor.Tests/js)
โโโ TwBlazor.Tests/ # Component library unit tests (bUnit + xunit + JS/vitest)
โโโ TwBlazor.Docs.Tests/ # Docs site and build tooling tests (pages, search, sitemap, XML docs)
โโโ TwBlazor.A11yTests/ # Accessibility (axe-core/Playwright) tests
docfx.json itself stays at the repository root (it's picked up by docfx docfx.json in
deploy-docs.yml), but its src/resource paths point into
src/TwBlazor and docs/TwBlazor.Docs above.
๐งฑ Top-Level Folders
/srcโ the published component library (TwBlazor,TwBlazor.Theme)/buildโ build-time tooling (TwBlazor.BuildTools,TwBlazor.Docs.Compiler)/docsโ documentation content, site hosts, and docfx config (TwBlazor.Docs,TwBlazor.Server,TwBlazor.WASM,TwBlazor.WasmHost,templates/,toc.yml)/testsโ automated tests (TwBlazor.Tests,TwBlazor.Docs.Tests,TwBlazor.A11yTests,vitest.config.js)
See Project Structure above for the full tree.
๐ Getting Started
Run these commands from the root of the repository.
Run the docs site (Blazor Server)
dotnet run --project docs/TwBlazor.Server
Run the docs site (Blazor WebAssembly)
dotnet run --project docs/TwBlazor.WasmHost
This serves the compiled TwBlazor.Wasm app via the TwBlazor.WasmHost host project.
Tip: swap
dotnet runfordotnet watch runon either command to get automatic rebuilds on file changes. Console output will show the local URL to browse to (e.g.https://localhost:xxxx).
Run the tests
dotnet test tests/TwBlazor.Tests
dotnet test tests/TwBlazor.Docs.Tests
Run the accessibility tests (optional)
The accessibility tests start the docs site and scan every component page with axe-core in a real browser, in light and dark mode. They are slower than the tests above and need a browser installed, so they are optional: pull request checks only run them when asked. Run them when you change how a component renders, its ARIA attributes, its keyboard handling or its colors.
On your machine: build once, install the browser once, then run the tests.
dotnet build tests/TwBlazor.A11yTests
pwsh tests/TwBlazor.A11yTests/bin/Debug/net11.0/playwright.ps1 install chromium
dotnet test tests/TwBlazor.A11yTests
On your pull request: tick Run the accessibility tests in the pull request description before you open it. The checks then run them after the unit and docs tests. If the pull request is already open, tick the box and push another commit.
On your fork, without a pull request: open the Actions tab of your fork, choose Accessibility Tests, select Run workflow and pick your branch. This needs no secrets, so it works on any fork.
They always run when a change is merged into develop or main.
Rebuild the doc examples
Code snippets shown on the documentation site are extracted from real source (docs pages and a few production files) by TwBlazor.BuildTools. See CODE_SNIPPETS.md for how this works. This runs automatically before TwBlazor.Docs builds, but you can trigger it manually if generated snippets look stale:
dotnet run --project build/TwBlazor.BuildTools
The same run writes llms.txt, llms-full.txt and a Markdown copy of every docs page (e.g. button.md) into docs/TwBlazor.WASM/wwwroot for AI assistants. They are gitignored and built from the docs pages, components.json and the library's [Parameter] XML docs, so they update themselves. To change the rules or setup steps at the top of llms.txt, edit llms.template.txt and the shared text in Partials.
The agent skills under /skills are built the same way, one per template in Skills. A template starts with name, description and references frontmatter: the routes of the docs pages to bundle with the skill, or components for every component page. Add a template to add a skill; the AI Agents & Skills page lists it automatically.
CSS
TwBlazor itself ships no pre-built stylesheet. Since Tailwind can't compile classes from a .DLL, every
class TwBlazor's components use is expressed as a literal in src/TwBlazor.Theme/Theme.cs
instead, and a consuming app builds its own Tailwind output from its own copy of that file - see the
"Get Started" guide for the consumer-facing side of this.
The only CSS actually built inside this repo is the documentation site's own. The easiest way is the
custom watch-tailwind.ps1 PowerShell script in the root of the repository, which builds it and
watches for changes to the input CSS file, rebuilding as necessary:
.\watch-tailwind.ps1
You can also build it manually:
cd ./docs/TwBlazor.Docsnpx @tailwindcss/cli -i ./wwwroot/css/input.css -o ./wwwroot/css/output.css --watch
NOTE: You may also have to run a clean and rebuild of the solution to ensure the new CSS file is picked up by the project if building manually, we advise you use watch-tailwind.ps1 detailed above.
๐งโ๐ป Coding Guidelines
Do:
- Write clean, readable code
- Keep components simple and focused
- Add comments for public APIs
- Follow existing patterns
Don't:
- Put complex logic in property getters/setters
- Modify component state unpredictably
- Break existing functionality
๐งฉ Component Guidelines (if applicable)
- Keep parameters simple (no hidden side effects)
- Use clear naming
- Avoid directly mutating inputs-use events/callbacks instead
- Keep UI and logic separated where possible
๐ Adding a New Component
A new component touches four places: the component itself, its docs page, its
tests, and an entry in components.json. Using TwTreeList
as a reference:
Component - add
src/TwBlazor/Components/<Name>/Tw<Name>.razor(and.razor.cscode-behind). Follow the Component Guidelines above.Docs page - add
docs/TwBlazor.Docs/Pages/<Name>/<Name>.razorshowing the component's variants/states. This is the page real users see, and is also what the accessibility tests scan (see below).Tests - add
tests/TwBlazor.Tests/Components/<Name>/Tw<Name>Tests.csfollowing the Testing naming conventions below.Register it in
components.json- add an entry to the appropriate category array at the repo root:{ "id": "my-component-navitem", "display": "My Component", "name": "TwMyComponent", "url": "/my-component" }id- unique DOM/nav id, conventionally<kebab-name>-navitemdisplay- label shown in the docs sidebarname- the component's C# type nameurl- route of the docs page from step 2isNew(optional) - settrueto show a "New" badge in the sidebar
components.json is the single source of truth that indexes every documented
component, and is consumed in two places:
- Docs navigation -
Navigation.razor.csdeserializes it (via an embedded resource) to build the sidebar. Category order and item order in the file are exactly the order rendered. - Accessibility tests -
AccessibilityRoutes.csreads the same embedded resource to enumerate every component'surland runs an axe-core scan against it in both light and dark mode. Adding your component's route tocomponents.jsonis what gets it covered by these tests automatically - no separate test wiring is needed.
Since components.json is embedded as a resource in TwBlazor.Docs.csproj,
no project file changes are required beyond editing the JSON itself.
๐งช Testing
- Add tests for any non-trivial logic
- Ensure all tests pass before submitting
- Keep tests:
- Small
- Independent
- Descriptive
Naming
Subject_Action_ExpectedResult- use the full component or method name as the subject
Examples:TwDataTable_Renders_WithEmptyItemsTwDataTable_Pageable_ShowsPaginationControlsUpdateApplication_DoesNothing_WhenOptionsIsNull
๐ฟ Branching Strategy
We follow a develop-main workflow:
mainโ Production-ready code, tagged releases onlydevelopโ Integration branch for all features and fixesfeature/*โ New features (e.g.,feature/toast-component)bug/*โ Bug fixes (e.g.,bug/fix-modal-close)chore/*โ Maintenance, tooling, tests and docs (e.g.,chore/arch-tests)
Merge Flow
feature/my-feature โ develop โ main
bug/my-fix โ โ
Important:
- โ
PRs from
feature/*,bug/*orchore/*โdevelop - โ
PRs from
developโmain(releases only) - โ Direct PRs to
mainfrom feature/bug/chore branches are blocked
๐ Pull Requests
- Keep PRs focused on a single change
- Fork the repo and create a feature branch from
develop:feature/my-featurebug/my-bugchore/my-chore
- Always target
developfor feature/bug PRs - Make sure:
- Project builds
- Tests pass
- Add tests when changing logic
- Link related issues (e.g. Fixes #123)
- Include screenshots/gifs for UI changes
- Avoid unrelated refactoring
PR title
Every PR title is checked by an automated Lint PR check and must follow Conventional Commits format:
<type>(<optional scope>)<optional !>: <subject>.
- Valid types:
feat,fix,bug,docs,style,refactor,perf,test,build,ci,chore,revert - The subject (the part after
type:) must be 10 to 100 characters - The subject must end with a full stop
- Add
!before the colon to mark a breaking change
Examples:
feat(button): add outlined variant.fix(modal): resolve close event not firing.chore: update dependencies.feat(tooltip)!: added new TwTooltip component.
โ ๏ธ PRs with titles that don't follow this format will fail the automated
Lint PRcheck.
PR description
Opening a PR prefills the description from
.github/pull_request_template.md. The same
Lint PR check requires every section to actually be filled in:
- Changes, what does this PR change?
- Testing, how was it verified?
- Checklist, the "I have read the Contributing Guidelines and Code of Conduct" item must be ticked
An unedited template, a section left as just the placeholder comment, or an unticked contributing-guidelines item will fail the check.
๐ฆ Releasing & Versioning
Versions are not stored in a file: they come entirely from Git tags, read at build time by MinVer. You never need to bump a version number by hand.
develop โ GitHub Packages (preview)
Every push to develop builds and publishes a prerelease NuGet package to
the GitHub Packages feed
automatically, versioned like 1.2.1-preview.4. This happens on every merge, so
you don't need to do anything to get a preview package out.
develop โ main โ NuGet.org (release)
A release is just a pull request from develop into main:
Open the PR as usual (see Pull Requests above).
Check the bump label.
release:patchis added automatically when the PR is opened, so a patch release needs no action. For anything else, remove it and add the one you want:release:major, for breaking changes, e.g.1.2.3โ2.0.0release:minor, for backwards compatible changes, e.g.1.2.3โ1.3.0release:patch, for fixes only, e.g.1.2.3โ1.2.4(the default)
Exactly one is required. Applying two, say
release:majoralongsiderelease:minor, makes the version ambiguous and fails the Verify Release Bump Label check, as does removing all of them. Other labels such asbugare ignored. A bot comments on the PR with the bump currently selected.Merge the PR.
Merging automatically:
- Tags the merge commit with the new version (e.g.
v1.2.0) - Publishes the stable package to both GitHub Packages and NuGet.org
- Creates a GitHub Release with the packed
.nupkgattached - Asks twblazor.templates to
release the same version, with its
Theme.csand package references synced to this release
The two packages share version numbers. If twblazor.templates has had a release
of its own since the last twblazor release (say templates 3.1.2 while twblazor
is on 3.1.1), the bump is applied to the higher of the two, so a patch release
becomes 3.1.3 and both packages match again.
There is nothing further to do on develop afterwards. Its next build picks
up the new release tag on its own and continues previewing from there (e.g.
1.2.1-preview.0, then .1, and so on).
๐ซ Common Mistakes
- Mixing multiple changes in one PR
- Skipping tests for logic changes
- Breaking existing behaviour
- Large PRs without prior discussion
๐ฌ Before Large Changes
Open an issue first to discuss your idea.
๐ Keeping Your Branch Updated
- Pull latest changes from the main branch regularly
- Resolve conflicts early
๐ค CI / Checks
All PRs must pass:
- Build
- Tests
- Linting, formatting and SonarCloud checks
โ Quick Checklist
Before submitting:
- [ ] Code builds
- [ ] Tests pass
- [ ] Tests added
- [ ] PR is focused
- [ ] Issue linked