---
name: effectified-material-web
description: Use @material/web in Effect UI apps through @effectified/material-web. Use when an Effect UI view renders @material/web: what the facade offers, how its bindings and mounts work, and tested examples.
---

# @material/web through @effectified/material-web

Inherited properties read from its types, a form and a dialog.

@material/web for Effect UI: typed bindings and mounts, its events as messages, its instances scoped to their elements. Generated from @material/web's own types (this copy: 2.5.0+3, for @material/web 2.5.0), so its types are upstream's and a call the facade does not change behaves as upstream documents.

## Install

```sh
pnpm add https://effectified.dev/material-web.tgz effect https://pkg.pr.new/Effect-TS/ui/@effect/ui@2fd1a57
```

## Rules

- Import from `@effectified/material-web`. It runs in [Effect UI](https://ui.effect.website) views (`Html.component`), installed from its snapshot build.
- Elements are bindings: `AssistChip(h)` renders `<md-assist-chip>`; set its properties as methods (`AssistChip(h).alwaysFocusable(...)`) and turn its custom events into messages with `.on("<event>", (detail) => Message.X(...))`. Importing a binding defines its element.
- Form controls report their state through their changes mount, not native `input`/`change` (Effect UI types those `never` on custom elements): `Checkbox(h).onMount(CheckboxChanges({}).pipe(Mount.map((state) => Message.X(state))))`, with `value`, `checked`, `indeterminate`.
- Set the Model from the event that says a change is done (an element that animates closed fires a request event, then a completion event): setting it on the request asks again.
- Never reach into the element or instance to change what the Model owns: render the Model, and let messages change it.

## Examples

Each is code from a test that passes in CI.

### A form and a dialog

```ts
import { Mount, UiSchema } from "@effect/ui";
import { BrowserHost, Html } from "@effect/ui/html";
import { Effect, Layer, Schema } from "effect";
import { Checkbox, CheckboxChanges, Dialog, FilledButton, OutlinedTextField, OutlinedTextFieldChanges, Slider, SliderChanges, Switch, SwitchChanges, TextButton } from "@effectified/material-web";

const Message = UiSchema.TaggedEnum({
	ChangedName: { name: Schema.String },
	ToggledNotify: { notify: Schema.Boolean },
	CheckedAgreed: { agreed: Schema.Boolean },
	MovedVolume: { volume: Schema.Number },
	ClickedOpen: {},
	OpenedDialog: {},
	ClosedDialog: {},
});

const Form = Html.component({
	name: "Form",
	model: Schema.Struct({
		name: Schema.String,
		notify: Schema.Boolean,
		agreed: Schema.Boolean,
		volume: Schema.Number,
		open: Schema.Boolean,
		dialog: Schema.Literals(["closed", "opened"]),
		closings: Schema.Number,
	}),
	message: Message,
}).make({
	init: () => ({ name: "", notify: false, agreed: false, volume: 50, open: false, dialog: "closed" as const, closings: 0 }),
	update: {
		ChangedName: ($, { name }) => $.evolve({ name: () => name }),
		ToggledNotify: ($, { notify }) => $.evolve({ notify: () => notify }),
		CheckedAgreed: ($, { agreed }) => $.evolve({ agreed: () => agreed }),
		MovedVolume: ($, { volume }) => $.evolve({ volume: () => volume }),
		ClickedOpen: ($) => $.evolve({ open: () => true }),
		OpenedDialog: ($) => $.evolve({ dialog: () => "opened" as const }),
		ClosedDialog: ($) => $.evolve({ open: () => false, dialog: () => "closed" as const, closings: (closings) => closings + 1 }),
	},
	view: (h, model) =>
		h.div.children(
			OutlinedTextField(h)
				.id("name")
				.label("Name")
				.value(model.name)
				.onMount(OutlinedTextFieldChanges({}).pipe(Mount.map(({ value }) => Message.ChangedName({ name: value })))),
			Switch(h)
				.id("notify")
				.selected(model.notify)
				.onMount(SwitchChanges({}).pipe(Mount.map(({ selected }) => Message.ToggledNotify({ notify: selected })))),
			Checkbox(h)
				.id("agreed")
				.checked(model.agreed)
				.onMount(CheckboxChanges({}).pipe(Mount.map(({ checked }) => Message.CheckedAgreed({ agreed: checked })))),
			Slider(h)
				.id("volume")
				.min(0)
				.max(100)
				.step(10)
				.value(model.volume)
				.onMount(SliderChanges({}).pipe(Mount.map(({ value }) => Message.MovedVolume({ volume: value ?? 0 })))),
			FilledButton(h).id("open").on("click", () => Message.ClickedOpen()).children("Open"),
			Dialog(h)
				.id("dialog")
				.open(model.open)
				.on("opened", () => Message.OpenedDialog())
				.on("closed", () => Message.ClosedDialog())
				.children(
					h.div.attr("slot", "headline").children("Hello"),
					h.div.attr("slot", "content").children(`Hello, ${model.name}`),
					h.div.attr("slot", "actions").children(TextButton(h).id("ok").children("OK")),
				),
			h.output.id("state").children(JSON.stringify(model)),
		),
});

Layer.launch(BrowserHost.mount(Form, {}, document.getElementById("root")!)).pipe(Effect.runFork);
```

From `test/fixtures/form.ts`.

## API

| Error | From |
|---|---|
| `MaterialWebError` | any other failure |

| Element | Binding | Properties | Events |
|---|---|---|---|
| `<md-assist-chip>` | `AssistChip` | `alwaysFocusable`, `disabled`, `download`, `elevated`, `hasIcon`, `href`, `label`, `softDisabled`, `target` | – |
| `<md-badge>` | `Badge` | `value` | – |
| `<md-branded-fab>` | `BrandedFab` | `label`, `lowered`, `size`, `variant` | – |
| `<md-checkbox>` | `Checkbox`, `CheckboxChanges` | `checked`, `disabled`, `indeterminate`, `name`, `required`, `value` | – |
| `<md-chip-set>` | `ChipSet` | – | – |
| `<md-circular-progress>` | `CircularProgress` | `fourColor`, `indeterminate`, `max`, `value` | – |
| `<md-dialog>` | `Dialog` | `noFocusTrap`, `open`, `quick`, `returnValue`, `type` | `closed`, `open`, `opened` |
| `<md-divider>` | `Divider` | `inset`, `insetEnd`, `insetStart` | – |
| `<md-elevated-button>` | `ElevatedButton` | `disabled`, `download`, `hasIcon`, `href`, `name`, `softDisabled`, `target`, `trailingIcon`, `type`, `value` | – |
| `<md-elevated-card>` | `ElevatedCard` | – | – |
| `<md-elevation>` | `Elevation` | – | – |
| `<md-fab>` | `Fab` | `label`, `lowered`, `size`, `variant` | – |
| `<md-filled-button>` | `FilledButton` | `disabled`, `download`, `hasIcon`, `href`, `name`, `softDisabled`, `target`, `trailingIcon`, `type`, `value` | – |
| `<md-filled-card>` | `FilledCard` | – | – |
| `<md-filled-icon-button>` | `FilledIconButton`, `FilledIconButtonChanges` | `ariaLabelSelected`, `disabled`, `download`, `flipIconInRtl`, `href`, `name`, `selected`, `softDisabled`, `target`, `toggle`, `type`, `value` | – |
| `<md-filled-select>` | `FilledSelect`, `FilledSelectChanges` | `clampMenuWidth`, `disabled`, `displayText`, `error`, `errorText`, `hasLeadingIcon`, `label`, `menuAlign`, `menuPositioning`, `name`, `noAsterisk`, `quick`, `required`, `selectedIndex`, `supportingText`, `typeaheadDelay`, `value` | `closed`, `closing`, `opened`, `opening` |
| `<md-filled-text-field>` | `FilledTextField`, `FilledTextFieldChanges` | `autocomplete`, `cols`, `error`, `errorText`, `hasLeadingIcon`, `hasTrailingIcon`, `label`, `max`, `maxLength`, `min`, `minLength`, `multiple`, `noAsterisk`, `noSpinner`, `pattern`, `placeholder`, `prefixText`, `readOnly`, `required`, `rows`, `step`, `suffixText`, `supportingText`, `textDirection`, `type`, `value` | – |
| `<md-filled-tonal-button>` | `FilledTonalButton` | `disabled`, `download`, `hasIcon`, `href`, `name`, `softDisabled`, `target`, `trailingIcon`, `type`, `value` | – |
| `<md-filled-tonal-icon-button>` | `FilledTonalIconButton`, `FilledTonalIconButtonChanges` | `ariaLabelSelected`, `disabled`, `download`, `flipIconInRtl`, `href`, `name`, `selected`, `softDisabled`, `target`, `toggle`, `type`, `value` | – |
| `<md-filter-chip>` | `FilterChip` | `alwaysFocusable`, `disabled`, `elevated`, `hasIcon`, `hasSelectedIcon`, `label`, `removable`, `selected`, `softDisabled` | `remove` |
| `<md-focus-ring>` | `FocusRing` | `inward`, `visible` | `visibility-changed` |
| `<md-icon>` | `Icon` | – | – |
| `<md-icon-button>` | `IconButton`, `IconButtonChanges` | `ariaLabelSelected`, `disabled`, `download`, `flipIconInRtl`, `href`, `name`, `selected`, `softDisabled`, `target`, `toggle`, `type`, `value` | – |
| `<md-input-chip>` | `InputChip` | `alwaysFocusable`, `avatar`, `disabled`, `hasIcon`, `href`, `label`, `removeOnly`, `selected`, `softDisabled`, `target` | `remove` |
| `<md-item>` | `Item` | `multiline` | – |
| `<md-linear-progress>` | `LinearProgress` | `buffer`, `fourColor`, `indeterminate`, `max`, `value` | – |
| `<md-list>` | `List` | – | – |
| `<md-list-item>` | `ListItem` | `disabled`, `href`, `isListItem`, `target`, `type` | – |
| `<md-menu>` | `Menu` | `anchor`, `anchorCorner`, `defaultFocus`, `hasOverflow`, `isSubmenu`, `menuCorner`, `noHorizontalFlip`, `noNavigationWrap`, `noVerticalFlip`, `open`, `positioning`, `quick`, `skipRestoreFocus`, `stayOpenOnFocusout`, `stayOpenOnOutsideClick`, `typeaheadController`, `typeaheadDelay`, `xOffset`, `yOffset` | `closed`, `closing`, `opened`, `opening` |
| `<md-menu-item>` | `MenuItem` | `disabled`, `href`, `keepOpen`, `selected`, `target`, `type` | `close-menu` |
| `<md-navigation-bar>` | `NavigationBar` | `activeIndex`, `hideInactiveLabels` | `navigation-bar-activated` |
| `<md-navigation-tab>` | `NavigationTab` | `active`, `badgeValue`, `disabled`, `hideInactiveLabel`, `label`, `showBadge` | `navigation-tab-interaction`, `navigation-tab-rendered` |
| `<md-outlined-button>` | `OutlinedButton` | `disabled`, `download`, `hasIcon`, `href`, `name`, `softDisabled`, `target`, `trailingIcon`, `type`, `value` | – |
| `<md-outlined-card>` | `OutlinedCard` | – | – |
| `<md-outlined-icon-button>` | `OutlinedIconButton`, `OutlinedIconButtonChanges` | `ariaLabelSelected`, `disabled`, `download`, `flipIconInRtl`, `href`, `name`, `selected`, `softDisabled`, `target`, `toggle`, `type`, `value` | – |
| `<md-outlined-segmented-button>` | `OutlinedSegmentedButton` | `disabled`, `hasIcon`, `label`, `noCheckmark`, `selected` | `segmented-button-interaction` |
| `<md-outlined-segmented-button-set>` | `OutlinedSegmentedButtonSet` | `multiselect` | `segmented-button-set-selection` |
| `<md-outlined-select>` | `OutlinedSelect`, `OutlinedSelectChanges` | `clampMenuWidth`, `disabled`, `displayText`, `error`, `errorText`, `hasLeadingIcon`, `label`, `menuAlign`, `menuPositioning`, `name`, `noAsterisk`, `quick`, `required`, `selectedIndex`, `supportingText`, `typeaheadDelay`, `value` | `closed`, `closing`, `opened`, `opening` |
| `<md-outlined-text-field>` | `OutlinedTextField`, `OutlinedTextFieldChanges` | `autocomplete`, `cols`, `error`, `errorText`, `hasLeadingIcon`, `hasTrailingIcon`, `label`, `max`, `maxLength`, `min`, `minLength`, `multiple`, `noAsterisk`, `noSpinner`, `pattern`, `placeholder`, `prefixText`, `readOnly`, `required`, `rows`, `step`, `suffixText`, `supportingText`, `textDirection`, `type`, `value` | – |
| `<md-primary-tab>` | `PrimaryTab` | `active`, `hasIcon`, `iconOnly`, `inlineIcon`, `selected` | – |
| `<md-radio>` | `Radio`, `RadioChanges` | `checked`, `disabled`, `name`, `required`, `value` | – |
| `<md-ripple>` | `Ripple` | `disabled` | – |
| `<md-secondary-tab>` | `SecondaryTab` | `active`, `hasIcon`, `iconOnly`, `selected` | – |
| `<md-select-option>` | `SelectOption` | `disabled`, `isMenuItem`, `selected`, `value` | `close-menu` |
| `<md-slider>` | `Slider`, `SliderChanges` | `ariaLabelEnd`, `ariaLabelStart`, `ariaValueTextEnd`, `ariaValueTextStart`, `disabled`, `labeled`, `max`, `min`, `name`, `range`, `step`, `ticks`, `value`, `valueEnd`, `valueLabel`, `valueLabelEnd`, `valueLabelStart`, `valueStart` | – |
| `<md-sub-menu>` | `SubMenu` | `anchorCorner`, `hoverCloseDelay`, `hoverOpenDelay`, `isSubMenu`, `menuCorner` | – |
| `<md-suggestion-chip>` | `SuggestionChip` | `alwaysFocusable`, `disabled`, `download`, `elevated`, `hasIcon`, `href`, `label`, `softDisabled`, `target` | – |
| `<md-switch>` | `Switch`, `SwitchChanges` | `disabled`, `icons`, `name`, `required`, `selected`, `showOnlySelectedIcon`, `value` | – |
| `<md-tabs>` | `Tabs` | `activeTabIndex`, `autoActivate` | – |
| `<md-text-button>` | `TextButton` | `disabled`, `download`, `hasIcon`, `href`, `name`, `softDisabled`, `target`, `trailingIcon`, `type`, `value` | – |

More: https://effectified.dev/material-web
