Charm UX
The work. Charm UX began as an internal Microsoft library and is now public. @charm-ux/core is 30+ accessible, headless Lit components. @charm-ux/fui is the Fluent-aligned set on top. I contribute to the core components. I do not maintain the whole library.
This portfolio is one consumer. Buttons, cards, badges, breadcrumbs, radios, and the token drawer are ch-* elements registered from @charm-ux/core 0.4.0. The look is a theme override. Component CSS is not forked.
Token architecture
The drawer writes three custom properties and one attribute on :root: --accent-h, --accent-s, --radius, and data-theme (light, dark, or contrast). theme.css rebuilds Charm's primary ramp from those variables. A mid step looks like this:
--color-primary-500: oklch(0.6 calc(0.17 * var(--accent-s) / 100) var(--accent-h));
Shape tokens are multiples of --radius, including --button-border-radius, --card-border-radius, and --dialog-border-radius. The hero diagram uses the same accent, so the exploded button and the live components recolor together. Values persist in localStorage under kham.tokens. Reset restores hue 39, saturation 120, radius 4, and the dark theme.
High contrast is a separate contract. data-theme="contrast" sets a fixed turquoise ramp and a 2px border. The drawer disables hue, saturation, and radius while that theme is on, so the sliders cannot paint over the forced palette.
Focus management
The drawer is a ch-dialog with position="end". In @charm-ux/core 0.4.0 the dialog's FocusTrapController is commented out, and the inner <dialog> is tabindex="0" while open. Tab stops on that empty shell between the real controls. src/lib/tokens.ts replaces that cycle while the drawer is fully open.
- Who is in the trap. The list is the close button in the shadow root (
part="dialog-close-button"), then the light-DOMch-radioelements, range inputs, andch-buttonelements. Disabled, hidden, or zero-size nodes are dropped. - Open. On
dialog-after-show, the inner dialog's tabindex is set to-1and focus moves to the first control in that list. - Tab. A capture-phase listener on
documenthandles Tab and Shift+Tab. The active element is resolved through open shadow roots, the index wraps, and the event is stopped so focus cannot land on the shell or leave the drawer. - Escape and the close button. Escape asks Charm to close with source
keyboard. Enter or Space on the close button is also a keyboard close: keydown sets a flag, and pointerdown clears it, so a mouse click on the X is not treated as a keyboard close. - Return focus. The Tokens button is focused only after the inner dialog is no longer
:modal. Moving it earlier loses the focus to the top layer, which parks it on the dialog shell. A pointer close blurs the button if focus was left there, so a mouse user does not keep a focus ring.
A focusin listener pulls focus back if it leaves the pane. It does not fight focus that is already on the Tokens button, which is what lets the keyboard restore finish.
What transfers
A headless component set is only as good as the token contract in front of it. I theme Charm by overriding that contract, and I fill the accessibility gap the installed dialog leaves open instead of forking the component.