This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Button

A button component that can be rendered as another tag or focusable when disabled.

Examples#

Rendering as another tag#

The button can remain keyboard accessible while being rendered as another tag, such as a <div>, by specifying tag="div".

Loading states#

For buttons that enter a loading state after activation, specify focusableWhenDisabled so focus remains on the button while it is disabled. Because some browser and screen reader combinations do not reliably announce changes to a focused button’s descendant text, use aria-labelledby to make the changing text the button’s explicit accessible name.

This example sends events to the server: PHP runs in your browser.

API reference#

Import the components of the family:

use function Phem\Ui\Button;

Button#

A button: Base UI Button.

With focusableWhenDisabled, a disabled button keeps the focus (for a loading state): it gets aria-disabled in place of disabled. A button with aria-disabled="true" has the disabled look, also when phem:lock locks it while its event runs.

A button with another tag (tag="div"), and a button with focusableWhenDisabled, use the phem-button controller: Enter and Space click the button, and a disabled button does nothing.

The triggers and the close buttons of the other components render this Button, so a replacement of it (#[Component(replaces: Button::class)]) changes them too.

Do not render a link with tag="a": a link has its own semantics, and tag needs a tag that can take the semantics of a button. Style the <a> element directly when a link must look like a button.

PropTypeDefault
disabledboolfalse
focusableWhenDisabledboolfalse
tagstring'button'
children?Htmlnull
...restmixed—

The source of the examples: examples/ui/Button.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close