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

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 run for dotnet watch run on 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.Docs
  • npx @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:

  1. Component - add src/TwBlazor/Components/<Name>/Tw<Name>.razor (and .razor.cs code-behind). Follow the Component Guidelines above.

  2. Docs page - add docs/TwBlazor.Docs/Pages/<Name>/<Name>.razor showing the component's variants/states. This is the page real users see, and is also what the accessibility tests scan (see below).

  3. Tests - add tests/TwBlazor.Tests/Components/<Name>/Tw<Name>Tests.cs following the Testing naming conventions below.

  4. 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>-navitem
    • display - label shown in the docs sidebar
    • name - the component's C# type name
    • url - route of the docs page from step 2
    • isNew (optional) - set true to 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.cs deserializes 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.cs reads the same embedded resource to enumerate every component's url and runs an axe-core scan against it in both light and dark mode. Adding your component's route to components.json is 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_WithEmptyItems
    • TwDataTable_Pageable_ShowsPaginationControls
    • UpdateApplication_DoesNothing_WhenOptionsIsNull

๐ŸŒฟ Branching Strategy

We follow a develop-main workflow:

  • main โ†’ Production-ready code, tagged releases only
  • develop โ†’ Integration branch for all features and fixes
  • feature/* โ†’ 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/* or chore/* โ†’ develop
  • โœ… PRs from develop โ†’ main (releases only)
  • โŒ Direct PRs to main from 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-feature
    • bug/my-bug
    • chore/my-chore
  • Always target develop for 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 PR check.

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:

  1. Open the PR as usual (see Pull Requests above).

  2. Check the bump label. release:patch is 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.0
    • release:minor, for backwards compatible changes, e.g. 1.2.3 โ†’ 1.3.0
    • release:patch, for fixes only, e.g. 1.2.3 โ†’ 1.2.4 (the default)

    Exactly one is required. Applying two, say release:major alongside release:minor, makes the version ambiguous and fails the Verify Release Bump Label check, as does removing all of them. Other labels such as bug are ignored. A bot comments on the PR with the bump currently selected.

  3. 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 .nupkg attached
  • Asks twblazor.templates to release the same version, with its Theme.cs and 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