Introduction to components
The@wordpress/components package provides a library of generic WordPress components for creating common UI elements shared between screens and features of the WordPress dashboard.
These components are designed to be reusable, accessible, and consistent with WordPress design patterns.
Installation
Install the components package:@wordpress/babel-preset-default if needed.
Basic usage
Import components from the package root:Loading component styles
Many components include CSS styles that must be loaded for proper appearance.In WordPress
Add thewp-components stylesheet as a dependency:
In non-WordPress projects
Link directly to the built stylesheet:node_modules/@wordpress/components/build-style/style.css.
Component categories
The components package includes various UI elements:Common component types
Common component types
Input Components
Button- Buttons with various styles and sizesTextControl- Text input fieldsTextareaControl- Multiline text areasCheckboxControl- Checkbox inputsRadioControl- Radio button groupsSelectControl- Dropdown selectsToggleControl- Toggle switches
Layout Components
Panel- Collapsible panel containersPanelBody- Panel sectionsPanelRow- Panel rowsCard- Card containersCardBody- Card content areas
Feedback Components
Notice- User notificationsSnackbar- Temporary notificationsSpinner- Loading indicatorsPlaceholder- Content placeholders
Advanced Components
Popover- Floating popoversModal- Modal dialogsDropdown- Dropdown menusColorPicker- Color selectionDatePicker- Date selection
Block editor components
The@wordpress/block-editor package provides specialized components for the block editor.
Components in
@wordpress/block-editor are customized for editor use. Use @wordpress/components for general-purpose UI unless building an editor.Key block editor components
Component examples
Button component
Panel components
Modal component
ColorPicker component
Popover system
By default,Popover components render in an element appended to the document body.
Controlling popover placement
UsePopover.Slot to control where popovers render:
TypeScript usage
The package exports TypeScript types for components. Extract props types usingReact.ComponentProps:
Block editor specific components
The@wordpress/block-editor package provides components designed specifically for block development:
RichText component
For editable rich text content:InspectorControls
For block sidebar settings:BlockControls
For block toolbar controls:InnerBlocks
For nested block structures:The
InnerBlocks API governs child block usage and enables hierarchical block structures.Block hooks
The@wordpress/block-editor package provides essential hooks:
useBlockProps
Marks an element as a block wrapper:Use of
useBlockProps on the outermost element is required for blocks using API version 2 or higher.useInnerBlocksProps
Marks an element as an inner blocks wrapper:useBlockEditContext
Access block edit context:Component documentation
Comprehensive component documentation and interactive examples are available in Storybook:Accessibility
WordPress components follow accessibility best practices:- Keyboard navigation support
- ARIA attributes for screen readers
- Focus management
- Color contrast compliance
- Semantic HTML structure
Always test your components with keyboard navigation and screen readers to ensure accessibility.
Using components in WordPress
When building WordPress plugins, enqueue component dependencies:wp global:
Component status and transitions
The components package is evolving:WordPress is rewriting global components for the new
@wordpress/ui package. However, this is work in progress—continue using @wordpress/components until further notice.experimental tags or prefixes.
Form components and validation
DataForm integration
For editing dataset items, consider usingDataForm from @wordpress/dataviews:
Validated form components
For validation, use validated form components:Best practices
Component best practices
Component best practices
- Use semantic components - Choose components that match your intent
- Load required styles - Always enqueue component stylesheets
- Follow accessibility patterns - Use ARIA labels and keyboard navigation
- Check component status - Verify component stability in Storybook
- Use TypeScript types - Leverage TypeScript for type safety
- Test interactivity - Verify keyboard and screen reader support
- Manage dependencies - Properly declare script dependencies
- Use SlotFill for popovers - Control popover rendering locations
Next steps
- Explore the Data Layer for state management
- Learn about Extensibility patterns
- Understand Block Editor Architecture
- Deep dive into Blocks