# RSuite Documentation for LLMs
This file contains the complete documentation for RSuite (React Suite), a comprehensive React component library.
Generated on: 2025-11-21T04:10:20.368Z
RSuite Version: 6.0.0
Source: https://github.com/rsuite/rsuite
Documentation: https://rsuitejs.com/
## About RSuite
RSuite is a set of React components committed to providing high-quality and comprehensive React components to help developers quickly build web applications.
## Documentation Structure
This file contains:
- **Guide Documentation**: Getting started guides, usage instructions, and best practices
- **Component Documentation**: For each component, includes:
- Main documentation with component introduction and Props reference
- Usage examples and code fragments demonstrating different features
For each component, you'll find the main documentation with all examples, code fragments, and type definitions included inline, providing a complete reference in a single section.
---
================================================================================
# Components: Accordion - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/accordion/en-US/index.md
================================================================================
# Accordion
The Accordion component is used to expand and collapse the content area by clicking the title. It is often used to display a large amount of content in a limited space.
## Import
**Main import:**
```js
import { Accordion } from 'rsuite';
```
**Individual import:**
```js
import Accordion from 'rsuite/Accordion';
// (Optional) Import component styles.
import 'rsuite/Accordion/styles/index.css';
```
## Examples
### Basic
By default, multiple panels can be expanded. Click the title to expand or collapse the accordion panel area.
```js
import { Accordion, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Bordered
```js
import { Accordion, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Expand only one panel
When `defaultActiveKey` or `activeKey` is set, only one panel can be expanded.
```js
import { Accordion, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
`activeKey` can be controlled by `onSelect` callback.
```js
import { Accordion, Placeholder, ButtonGroup, Button } from 'rsuite';
const App = () => {
const [activeKey, setActiveKey] = React.useState(1);
return (
<>
{[1, 2, 3].map(key => (
))}
);
};
const App = () => (
}
eventKey={1}
>
React is a JavaScript library for building user interfaces.
Declarative: React makes it painless to create interactive UIs. Design
simple views for each state in your application, and React will efficiently update and
render just the right components when your data changes. Declarative views make your code
more predictable, simpler to understand, and easier to debug.
Component-Based: Build encapsulated components that manage their own state,
then compose them to make complex UIs. Since component logic is written in JavaScript
instead of templates, you can easily pass rich data through your app and keep the state out
of the DOM.
Learn Once, Write Anywhere: We don't make assumptions about the rest of
your technology stack, so you can develop new features in React without rewriting existing
code. React can also render on the server using Node and power mobile apps using React
Native.
}
eventKey={2}
>
Vue (pronounced /vjuː/, like view) is a JavaScript framework for building user interfaces. It
builds on top of standard HTML, CSS, and JavaScript and provides a declarative and
component-based programming model that helps you efficiently develop user interfaces, be they
simple or complex.
}
eventKey={3}
>
Angular is a web framework that empowers developers to build fast, reliable applications.
Maintained by a dedicated team at Google, Angular provides a broad suite of tools, APIs, and
libraries to simplify and streamline your development workflow. Angular gives you a solid
platform on which to build fast, reliable applications that scale with both the size of your
team and the size of your codebase.
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled Panel
```js
import { Accordion, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- `aria-expanded`: Indicates whether the panel is expanded or collapsed.
- `aria-controls`: Identifies the content that is controlled by the panel.
- `aria-labelledby`: Identifies the element that serves as the title for the panel.
- `aria-disabled`: Indicates that the panel is disabled.
### Keyboard interactions
- Tab: Move focus to the next focusable panel.
- Enter or Space: Expand or collapse the panel.
### Resources
- [ARIA Practices: Accordion Pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/)
## Props
### ``
| Property | Type `(Default)` | Description |
| ---------------- | --------------------------------- | -------------------------------------------- |
| activeKey | string | The active item's event key. |
| bordered | boolean | Show border. |
| classPrefix | string | The prefix of the component CSS class. |
| defaultActiveKey | string | The default active item's event key. |
| onSelect | (eventKey: string, event) => void | Callback fired when the active item changes. |
### ``
| Property | Type `(Default)` | Description |
| --------------- | ------------------ | ----------------------------------------- |
| bodyFill | boolean | Content area filled with containers. |
| caretAs | ReactNode | Custom indicator. |
| classPrefix | string `('panel')` | The prefix of the component CSS class. |
| defaultExpanded | boolean | Expand the panel by default. |
| disabled | boolean | Disable the panel. |
| eventKey | string | The event key corresponding to the panel. |
| expanded | boolean | Expand the panel. |
| header | ReactNode | The title of the panel. |
================================================================================
# Components: Affix - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/affix/en-US/index.md
================================================================================
# Affix
Components such as navigation, buttons, etc. can be fixed in the visible range. Commonly used for pages with long content, fixed the specified elements in the visible range of the page to assist in quick operation.
## Import
**Main import:**
```js
import { Affix } from 'rsuite';
```
**Individual import:**
```js
import Affix from 'rsuite/Affix';
```
## Examples
### Basic
```js
import { Affix, Button, Placeholder } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Top
```js
import { Affix, Button, Placeholder } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Container
When the container is in the visible range, the element is fixed. When the scrolling page container is not in the visible range, the element is unfixed.
```js
import { Affix, Button, Placeholder } from 'rsuite';
const App = () => {
const container = React.useRef();
return (
<>
{
return container.current;
}}
>
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(Default)` | Description |
| ----------- | ---------------------------------- | ----------------------------------------------------------------------------------------------- |
| children | ReactNode | Fixed element. |
| classPrefix | string `('affix')` | The prefix of the component CSS class. |
| container | HTMLElement \| (() => HTMLElement) | Specify the container. An element can only be fixed when the container is in the visible range. |
| onChange | (fixed: boolean) => voide | Callback function when non-fixed and fixed state changes. |
| top | number `(0)` | Set the fixed top height. |
================================================================================
# Components: Animation - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/animation/en-US/index.md
================================================================================
# Animation
`Animation` component is a set of animation components. You can achieve animation effects by configuring related properties.
## Import
**Main import:**
```js
import { Animation } from 'rsuite';
```
**Individual import:**
```js
import Animation from 'rsuite/Animation';
// (Optional) Import component styles.
import 'rsuite/Animation/styles/index.css';
```
- `Animation.Fade` Fade animation.
- `Animation.Collapse` Collapse animation.
- `Animation.Bounce` Bounce animation.
- `Animation.Slide` Slide animation.
- `Animation.Transition` Custom animation.
## Examples
### Fade
```js
import { Animation, Button, Card } from 'rsuite';
const AnimatedPanel = React.forwardRef((props, ref) => (
Fade AnimationThis panel demonstrates a smooth fade transition effect.
);
};
function Styles() {
return (
);
}
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------------------ | ----------------------------------------------------------------- |
| enteredClassName | string | Adding a className after the component finished transtioning in |
| enteringClassName | string | Adding a className as the component begins to transition in |
| exitedClassName | string | Adding a className after the component finishes transitioning out |
| exitingClassName | string | Adding a className as the component begins to transition out |
| in | boolean | When true The animation will show itself |
| onEnter | (node?: null, Element, Text) => void | Callback fired before the component transitions in |
| onEntered | (node?: null, Element, Text) => void | Callback fired after the component finishes transitioning in |
| onEntering | (node?: null, Element, Text) => void | Callback fired as the component begins to transition in |
| onExit | (node?: null, Element, Text) => void | Callback fired right before the component transitions out |
| onExited | (node?: null, Element, Text) => void | Callback fired after the Modal finishes transitioning out |
| onExiting | (node?: null, Element, Text) => void | Callback fired as the component begins to transition out |
| timeout | number `(300)` | Animation transition delay time |
| transitionAppear | boolean | Turn on transitions when initially displayed |
| unmountOnExit | boolean | Unmount component on exit |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | -------------------------------------------------------- | ----------------------------------------------------------------- |
| dimension | 'height'|'width'|() => ('height'|'width') | Set fold size type |
| enteredClassName | string `('collapse in')` | Adding a className after the component finished transtioning in |
| enteringClassName | string `('collapsing')` | Adding a className as the component begins to transition in |
| exitedClassName | string `('collapse')` | Adding a className after the component finishes transitioning out |
| exitingClassName | string `('collapsing')` | Adding a className as the component begins to transition out |
| getDimensionValue | () => number | Custom size value |
| in | boolean | When true The animation will show itself |
| onEnter | (node?: null, Element, Text) => void | Callback fired before the component transitions in |
| onEntered | (node?: null, Element, Text) => void | Callback fired after the component finishes transitioning in |
| onEntering | (node?: null, Element, Text) => void | Callback fired as the component begins to transition in |
| onExit | (node?: null, Element, Text) => void | Callback fired right before the component transitions out |
| onExited | (node?: null, Element, Text) => void | Callback fired after the Modal finishes transitioning out |
| onExiting | (node?: null, Element, Text) => void | Callback fired as the component begins to transition out |
| role | string | HTML role |
| timeout | number`(300)` | Animation transition delay time |
| transitionAppear | boolean | Turn on transitions when initially displayed |
| unmountOnExit | boolean | Unmount component on exit |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------------------ | ----------------------------------------------------------------- |
| enteredClassName | string | Adding a className after the component finished transtioning in |
| enteringClassName | string | Adding a className as the component begins to transition in |
| exitedClassName | string | Adding a className after the component finishes transitioning out |
| exitingClassName | string | Adding a className as the component begins to transition out |
| in | boolean | When true The animation will show itself |
| onEnter | (node?: null, Element, Text) => void | Callback fired before the component transitions in |
| onEntered | (node?: null, Element, Text) => void | Callback fired after the component finishes transitioning in |
| onEntering | (node?: null, Element, Text) => void | Callback fired as the component begins to transition in |
| onExit | (node?: null, Element, Text) => void | Callback fired right before the component transitions out |
| onExited | (node?: null, Element, Text) => void | Callback fired after the Modal finishes transitioning out |
| onExiting | (node?: null, Element, Text) => void | Callback fired as the component begins to transition out |
| timeout | number `(300)` | Animation transition delay time |
| transitionAppear | boolean | Turn on transitions when initially displayed |
| unmountOnExit | boolean | Unmount component on exit |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------------------ | ----------------------------------------------------------------- |
| enteredClassName | string | Adding a className after the component finished transtioning in |
| enteringClassName | string | Adding a className as the component begins to transition in |
| exitedClassName | string | Adding a className after the component finishes transitioning out |
| exitingClassName | string | Adding a className as the component begins to transition out |
| in | boolean | When true The animation will show itself |
| onEnter | (node?: null, Element, Text) => void | Callback fired before the component transitions in |
| onEntered | (node?: null, Element, Text) => void | Callback fired after the component finishes transitioning in |
| onEntering | (node?: null, Element, Text) => void | Callback fired as the component begins to transition in |
| onExit | (node?: null, Element, Text) => void | Callback fired right before the component transitions out |
| onExited | (node?: null, Element, Text) => void | Callback fired after the Modal finishes transitioning out |
| onExiting | (node?: null, Element, Text) => void | Callback fired as the component begins to transition out |
| timeout | number `(300)` | Animation transition delay time |
| transitionAppear | boolean | Turn on transitions when initially displayed |
| unmountOnExit | boolean | Unmount component on exit |
| placement | Placement `('right')` | The placement of component |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------------------ | ----------------------------------------------------------------- |
| enteredClassName | string | Adding a className after the component finished transtioning in |
| enteringClassName | string | Adding a className as the component begins to transition in |
| exitedClassName | string | Adding a className after the component finishes transitioning out |
| exitingClassName | string | Adding a className as the component begins to transition out |
| in | boolean | When true The animation will show itself. |
| onEnter | (node?: null, Element, Text) => void | Callback fired before the component transitions in |
| onEntered | (node?: null, Element, Text) => void | Callback fired after the component finishes transitioning in |
| onEntering | (node?: null, Element, Text) => void | Callback fired as the component begins to transition in |
| onExit | (node?: null, Element, Text) => void | Callback fired right before the component transitions out |
| onExited | (node?: null, Element, Text) => void | Callback fired after the Modal finishes transitioning out |
| onExiting | (node?: null, Element, Text) => void | Callback fired as the component begins to transition out |
| timeout | number`(1000)` | Animation transition delay time |
| transitionAppear | boolean | Turn on transitions when initially displayed |
| unmountOnExit | boolean | Unmount component on exit |
#### `ts:Placement`
```ts
type Placement = 'top' | 'bottom' | 'right' | 'left';
```
================================================================================
# Components: Auto Complete - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/auto-complete/en-US/index.md
================================================================================
# AutoComplete
Provide auto-complete functionality for input box.
## Import
**Main import:**
```js
import { AutoComplete } from 'rsuite';
```
**Individual import:**
```js
import AutoComplete from 'rsuite/AutoComplete';
// (Optional) Import component styles.
import 'rsuite/AutoComplete/styles/index.css';
```
## Examples
### Basic
```js
import { AutoComplete } from 'rsuite';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
];
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Autocomplete suffix
```js
import { AutoComplete } from 'rsuite';
const suffixes = ['@gmail.com', '@sina.com.cn', '@163.com', '@qq.com'];
const App = () => {
const [data, setData] = React.useState([]);
const handleChange = value => {
const at = value.match(/@[\S]*/);
const nextData = at
? suffixes
.filter(item => item.indexOf(at[0]) >= 0)
.map(item => {
return `${value}${item.replace(at[0], '')}`;
})
: suffixes.map(item => `${value}${item}`);
setData(nextData);
};
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { AutoComplete, VStack } from 'rsuite';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
];
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Render Item
```js
import { AutoComplete } from 'rsuite';
import MemberIcon from '@rsuite/icons/Member';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
];
const App = () => (
{
return (
{item}
);
}}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import { AutoComplete, VStack, HStack, Text, Divider } from 'rsuite';
const data = [];
const App = () => (
}>
Disabled
ReadOnly
Plaintext
);
ReactDOM.render(, document.getElementById('root'));
```
### Combined with InputGroup
```js
import { AutoComplete, InputGroup, VStack } from 'rsuite';
import SearchIcon from '@rsuite/icons/Search';
import MemberIcon from '@rsuite/icons/Member';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
];
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
```js
import { AutoComplete } from 'rsuite';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
];
const App = () => {
const [value, setValue] = React.useState('');
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- Autocomplete has role `combobox`.
- Has the `aria-haspopup="listbox"` attribute to indicate that the input has a popup listbox.
- Has the `aria-expanded` attribute to indicate whether the listbox is open or not.
- Has the `aria-controls` attribute to indicate the ID of the listbox element.
- Has the `aria-activedescendant` attribute to indicate the ID of the focused option.
### Keyboard interactions
- Down - Move focus to the next option.
- Up - Move focus to the previous option.
- Enter - Select the focused option.
- Esc - Close the listbox.
## Props
### ``
| Property | Type`(Default)` | Description |
| -------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| classPrefix | string `('auto-complete')` | The prefix of the component CSS class |
| data \* | [Option](#code-ts-item-data-type-code)[] \| string[] | The data of component |
| defaultValue | string | The default value (uncontrolled) |
| disabled | boolean | Whether disabled select |
| filterBy | (value: string, item: [Option](#code-ts-item-data-type-code)) => boolean | Custom filter rules (will only display items that value is a substring of which by default) |
| onChange | (value:string, event) => void | Called when select an option or input value change, or value of input is changed |
| onClose | () => void | Callback fired when hidden |
| onEnter | () => void | Callback fired before the overlay transitions in |
| onEntered | () => void | Callback fired after the overlay finishes transitioning in |
| onEntering | () => void | Callback fired as the overlay begins to transition in |
| onExit | () => void | Callback fired right before the overlay transitions out |
| onExited | () => void | Callback fired after the overlay finishes transitioning out |
| onExiting | () => void | Callback fired as the overlay begins to transition out |
| onSelect | (item: [Option](#code-ts-item-data-type-code), event) => void | Called when a option is selected. |
| placeholder | ReactNode | The placeholder of input |
| popupClassName | string | Custom class name for the popup |
| popupStyle | CSSProperties | Custom style for the popup |
| renderListbox | (listbox:ReactNode) => ReactNode | Custom render listbox |
| renderOption | (label:ReactNode, item: [Option](#code-ts-item-data-type-code)) => ReactNode | Custom render option |
| selectOnEnter | boolean `(true)` | When set to `false`, the Enter key selection function is invalid |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' | A component can have different sizes |
| value | string | The current value (controlled) |
#### `ts:Option`
```ts
interface Option {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: V;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/**
* The data of the child option corresponds to the `childrenKey` in the data.
* Properties owned by tree structure components, such as TreePicker, Cascader.
*/
children?: Option[];
/**
* Properties of grouping functional components, such as CheckPicker, InputPicker
*/
groupBy?: string;
/**
* The children under the current node are loading.
* Used for components that have cascading relationships and lazy loading of children. E.g. Cascader, MultiCascader
*/
loading?: boolean;
}
```
================================================================================
# Components: Avatar - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/avatar/en-US/index.md
================================================================================
# Avatar
Used to display an avatar or brand.
## Import
**Main import:**
```js
import { Avatar, AvatarGroup } from 'rsuite';
```
**Individual import:**
```js
import Avatar from 'rsuite/Avatar';
import AvatarGroup from 'rsuite/AvatarGroup';
// (Optional) Import component styles.
import 'rsuite/Avatar/styles/index.css';
import 'rsuite/AvatarGroup/styles/index.css';
```
## Examples
### Basic
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Character avatar
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
<>
RX👍
R
X
👍
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Icon avatars
```js
import { AvatarGroup, Badge, Avatar } from 'rsuite';
import { FaUserLarge } from 'react-icons/fa6';
import { FcBusinessman, FcCustomerSupport } from 'react-icons/fc';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Image avatars
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Bordered
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Color
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Avatar Fallbacks
If there is an error loading the src of the avatar, there are 2 fallbacks:
1. If there is an `alt` prop, the value of the alt attribute will be rendered.
2. If there is no `alt` prop, a default avatar will be rendered.
```js
import { AvatarGroup, Avatar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Stacked avatars
```js
import { AvatarGroup, Avatar } from 'rsuite';
const users = [
{ avatar: 'https://i.pravatar.cc/150?u=1', name: 'John Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=2', name: 'Tom Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=3', name: 'Jerry Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=4', name: 'Lily Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=5', name: 'Lucy Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=6', name: 'Mike Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=7', name: 'Jane Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=8', name: 'Kate Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=9', name: 'Jack Doe' },
{ avatar: 'https://i.pravatar.cc/150?u=10', name: 'Rose Doe' }
];
const max = 4;
const App = () => (
<>
{users.map(user => (
))}
{users
.filter((user, i) => i < max)
.map(user => (
))}
+{users.length - max}
>
);
ReactDOM.render(, document.getElementById('root'));
```
### With badge
```js
import { AvatarGroup, Badge, Avatar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type | Description | Version |
| ----------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ----------- |
| alt | string | This attribute defines the alternative text for the image avatar. | |
| bordered | boolean | Whether to show the border. | ![][5.59.0] |
| children | string \| Element | Content(It maybe text or icon). | |
| circle | boolean | Render a circle avatar. | |
| classPrefix | string `('avatar')` | The prefix of the component CSS class. | |
| color | [ColorScheme][color-scheme] \| CSSProperties['color'] | Set the background color of the avatar. | ![][5.59.0] |
| imgProps | object | Attributes applied to the `img` element if the component is used to display an image. | |
| onError | (event) => void | Callback when the image fails to load. | ![][5.59.0] |
| size | [Size][size] \| `('md')` | Size of avatar. | |
| sizes | string | The `sizes` attribute for the `img` element. | |
| src | string | The `src` attribute for the `img` element. | |
| srcSet | string | The `srcSet` attribute for the `img` element. Use this attribute for responsive image display. | |
### ``
| Property | Type`(Default)` | Description |
| -------- | --------------- | ------------------------------- |
| size | [Size][size] | Set the size of all avatars. |
| spacing | number | Set the spacing of the avatars. |
| stack | boolean | Render all avatars as stacks. |
#### `ts:ColorScheme`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
type ShadeValue = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
// Color with shade type (e.g., red.50, blue.500)
type ColorShade = `${Colours}.${ShadeValue}` | `${ColorGray}.${ShadeValue}`;
// Combined type that allows both basic colors and colors with shades
type ColorScheme = Color | ColorShade;
```
#### `ts:Size`
```ts
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
```
[color-scheme]: #code-ts-color-scheme-code
[size]: #code-ts-size-code
================================================================================
# Components: Badge - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/badge/en-US/index.md
================================================================================
# Badge
Used to display the number of unread messages or status on icons or other components.
## Usage
**Main import:**
```js
import { Badge } from 'rsuite';
```
**Individual import:**
```js
import Badge from 'rsuite/Badge';
// (Optional) Import component styles.
import 'rsuite/Badge/styles/index.css';
```
## Examples
### Basic
```js
import { Avatar, Badge } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With content
```js
import { Badge, Avatar, HStack } from 'rsuite';
import { MdCheck, MdNotifications, MdError } from 'react-icons/md';
import { BsExclamation } from "react-icons/bs";
const App = () => (
}>
}>
}>
);
ReactDOM.render(, document.getElementById('root'));
```
### Placement
```js
import { Avatar, Badge, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Shapes
If the wrapped element is a circle, you can use the `shape` property `circle` to make the Badge position more reasonable.
```js
import { Avatar, Badge, HStack, IconButton } from 'rsuite';
import { MdNotifications } from 'react-icons/md';
const App = () => (
<>
} size="sm" appearance="primary" />
} circle size="sm" appearance="primary" />
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Sizes
The Badge component supports different sizes through the `size` prop.
```js
import { Badge, Avatar, HStack } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Offset
If the Badge position is not reasonable, you can use the `offset` property to make fine adjustments.
```js
import { Avatar, Badge, HStack, IconButton } from 'rsuite';
import { MdNotifications } from 'react-icons/md';
const App = () => (
} circle appearance="subtle" />
);
ReactDOM.render(, document.getElementById('root'));
```
### Invisible
```js
import { Badge, Avatar, Toggle, HStack } from 'rsuite';
const App = () => {
const [show, setShow] = React.useState(true);
return (
<>
Show Badge
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Badge without children
```js
import { Badge, HStack } from 'rsuite';
import { MdCheck, MdNotifications } from 'react-icons/md';
import { BsExclamation } from 'react-icons/bs';
const App = () => (
<>
} />
} />
} />
Ready} />
Error
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Colors
```js
import { Badge, Avatar, HStack } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(Default)` | Description | Version |
| ----------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------- | ---------- |
| children | ReactNode | The wrapped component | |
| classPrefix | string `('badge')` | The prefix of the component CSS class | |
| color | [Color](#code-ts-color-code) \| CSSProperties['color'] | Set the color of the badge | |
| compact | boolean | Whether to use compact mode | ![][6.0.0] |
| content | number \| ReactNode | The content of the badge | |
| invisible | boolean | Whether the badge is invisible | ![][6.0.0] |
| maxCount | number`(99)` | Max count number(Only valid if `content` is type number) | |
| offset | [number,number] \| [string, string] | Define the horizontal and vertical offset of the badge relative to its wrapped element | ![][6.0.0] |
| outline | boolean`(true)` | Whether to use outline mode | ![][6.0.0] |
| placement | [PlacementCorners](#code-ts-placement-corners-code) | Set the position of the badge in the wrapped element | ![][6.0.0] |
| shape | 'rectangle' \| 'circle' | The shape of the wrapped element | ![][6.0.0] |
| size | 'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl' `('md')` | Set the size of the badge | |
#### `ts:Color`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
```
#### `ts:PlacementCorners`
```ts
type PlacementCorners = 'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd';
```
================================================================================
# Components: Box - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/box/en-US/index.md
================================================================================
# Box
Box component is the base component for all components, providing shorthand for style properties.
## Import
**Main import:**
```js
import { Box } from 'rsuite';
```
**Individual import:**
```js
import Box from 'rsuite/Box';
// (Optional) Import component styles.
import 'rsuite/Box/styles/index.css';
```
## Usage
```js
const App = () => (
This is the Box
);
```
## Examples
### Color and Background
```js
import { Box, HStack, VStack } from 'rsuite';
const App = () => (
<>
bg: blue.100c: blue.600bg: linear-gradient(45deg, #4CAF50, #2196F3)c: white
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Border and Rounded
```js
import { Box, HStack } from 'rsuite';
const App = () => (
This is the Box
This is the Box
);
ReactDOM.render(, document.getElementById('root'));
```
### Shadow
```js
import { Box, HStack } from 'rsuite';
const App = () => (
This is the Box
This is the Box
);
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
Box component supports responsive values for all shorthand CSS properties. This allows you to define different styles for different breakpoints.
```jsx
This box has responsive width, padding and display
```
## Props
### ``
| Property | Type`(default)` | Description |
| --------- | -------------------------- | ------------------------------------------------------------------- |
| as | ElementType `('div')` | Custom element type for the component |
| children | ReactNode | The content of the component |
| className | string | Additional CSS class |
| display | CSSProperties['display'] | CSS display property |
| hideFrom | [Breakpoints][breakpoints] | Breakpoint above which the component is hidden with `display: none` |
| showFrom | [Breakpoints][breakpoints] | Breakpoint below which the component is hidden with `display: none` |
| style | CSSProperties | Inline style |
### `Style Props`
The Box component provides a series of shorthand properties for more concise style settings. These properties directly map to their corresponding CSS properties.
See the [Style Props](/guide/style-props) documentation for a complete reference of style properties.
- **Theme Values**: Provided theme presets, such as ``, ``, etc.
- **Responsive Values**: Provided responsive values, such as ``, etc.
- **CSS Native Properties**: Provided CSS native properties, such as ``, ``, etc.
### Type Definitions
#### `ts:Breakpoints`
```ts
type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
```
[breakpoints]: #code-ts-breakpoints-code
================================================================================
# Components: Breadcrumb - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/breadcrumb/en-US/index.md
================================================================================
# Breadcrumb
Used to display the current page path and quickly return to the history page.
## Import
**Main import:**
```js
import { Breadcrumb } from 'rsuite';
```
**Individual import:**
```js
import Breadcrumb from 'rsuite/Breadcrumb';
// (Optional) Import component styles.
import 'rsuite/Breadcrumb/styles/index.css';
```
## Examples
### Basic
A basic example of breadcrumb navigation.
```js
import { Breadcrumb } from 'rsuite';
const App = () => (
HomeComponentsBreadcrumb
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
Breadcrumbs are available in different sizes to match your design needs.
```js
import { Breadcrumb, VStack } from 'rsuite';
const BreadcrumbBox = ({ size }) => (
HomeProductsElectronicsSmartphones{`${size}`}
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Icons
Add icons to breadcrumb items for enhanced visual cues.
```js
import { Breadcrumb } from 'rsuite';
import { GoHomeFill } from 'react-icons/go';
const App = () => (
}>Home
ComponentsBreadcrumb
);
ReactDOM.render(, document.getElementById('root'));
```
### With Background
Add background color to make breadcrumbs stand out on the page.
```js
import { Breadcrumb, Box } from 'rsuite';
import { GoHomeFill } from 'react-icons/go';
const App = () => (
}>Home
ComponentsBreadcrumb
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom separator
Replace the default separator with custom elements or icons.
```js
import Link from 'next/link';
import { Breadcrumb, VStack } from 'rsuite';
import { MdArrowRightAlt } from 'react-icons/md';
const BreadcrumbBox = ({ separator }) => (
Home
Components
Breadcrumb
);
const App = () => (
'} />
} />
);
ReactDOM.render(, document.getElementById('root'));
```
### With Expand
Should automatically collapse if there are more than 5 items. Use `maxItems` to set the maximum number of breadcrumbs to display.
```js
import { Breadcrumb } from 'rsuite';
const App = () => (
{
console.log('call onExpand');
}}
>
HomeLibraryDataComputer ScienceProgramming LanguagesJavaScript
);
ReactDOM.render(, document.getElementById('root'));
```
### Dropdown
Integrate dropdown menus with breadcrumb items for additional navigation options.
```js
import ArrowDownLineIcon from '@rsuite/icons/ArrowDownLine';
import { Breadcrumb, Dropdown, HStack } from 'rsuite';
const App = () => (
Home (
Components
)}
>
GuidesComponentsToolsBreadcrumb
);
ReactDOM.render(, document.getElementById('root'));
```
### Routing Library
The `Breadcrumb.Item` component can be used with other routing libraries (such as Next.js, React Router) through the `as` prop. See the [Composition Guide](https://rsuitejs.com/guide/composition/#react-router-dom) for details.
```js
import { Breadcrumb } from 'rsuite';
import Link from 'next/link';
const App = () => (
Home
Components
Breadcrumb
);
ReactDOM.render(, document.getElementById('root'));
```
### Accessibility
WAI-ARIA:https://www.w3.org/TR/wai-aria-practices/#breadcrumb
- `HomeComponentsBreadcrumb
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------------------------- | -------------------------------------------------------------------------------------- |
| as | ElementType `('nav')` | Custom element type for the component |
| classPrefix | string `('breadcrumb')` | The prefix of the component CSS class |
| locale | [BreadcrumbLocaleType](/guide/i18n/#breadcrumb) | Define localization settings to display component text in the user's regional language |
| maxItems | number `(5)` | Set the maximum number of breadcrumbs to display |
| onExpand | (event: MouseEvent) => void | Callback function when the ellipsis is clicked in the collapsed view |
| separator | ReactNode `('/')` | Custom separator between breadcrumb items |
| size | 'sm' \| 'md' \| 'lg' \| number \| string `('md')` | Set the size of breadcrumb items |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ---------------------------- | ----------------------------------------------------------------------- |
| active | boolean | Indicates if the breadcrumb item is active |
| as | ElementType `('a')` | Custom element type for the component. Defaults to 'a' if 'href' is set |
| classPrefix | string `('breadcrumb-item')` | The prefix of the component CSS class |
| href | string | When provided, renders the breadcrumb item as an anchor element |
| icon | ReactNode | Custom icon to display before the breadcrumb item text |
================================================================================
# Components: Button - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/button/en-US/index.md
================================================================================
# Button
Commonly used operating buttons。
## Import
**Main import:**
```js
import { Button } from 'rsuite';
```
**Individual import:**
```js
import Button from 'rsuite/Button';
// (Optional) Import component styles.
import 'rsuite/Button/styles/index.css';
```
- `Button` is the most basic element in the component, you can quickly create a styled button.
## Examples
### Basic
```js
import { Button } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
`appearance` property sets the button style, options includes: `default`, `primary`, `link`, `subtle`, `ghost`.
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Sizes
The `size` property sets the button size, options includes: `lg`, `md`, `sm`, `xs`.
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Colors
The `color` property sets the button style, Options include: `red`, `orange`, `yellow`, `green`, `cyan`, `blue`, `violet`.
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Icon before
Display an icon before the text.
```js
import { Button, ButtonToolbar } from 'rsuite';
import AddOutlineIcon from '@rsuite/icons/AddOutline';
import GearIcon from '@rsuite/icons/Gear';
const App = () => (
}> Add
}> Settings
);
ReactDOM.render(, document.getElementById('root'));
```
### Icon after
Display an icon after the text.
```js
import { Button, ButtonToolbar } from 'rsuite';
import { FaExternalLinkSquareAlt } from 'react-icons/fa';
import PageEndIcon from '@rsuite/icons/PageEnd';
const App = () => (
}> Open on new tab
}> Next page
);
ReactDOM.render(, document.getElementById('root'));
```
### Block
This is generally applicable to flow layouts, or to full rows at the top and bottom of a container.
```js
import { Button, IconButton, ButtonToolbar } from 'rsuite';
import AddOutlineIcon from '@rsuite/icons/AddOutline';
const App = () => (
}>
Block With Icon
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Active
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Toggleable
The Button is `toggleable`, allowing you to switch its state between active and inactive.
```js
import { Button, ButtonGroup } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Loading
```js
import { Button, ButtonToolbar } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA Properties
- Button has role of `button`.
### Keyboard interaction
- When Button has focus, Space or Enter activates it.
## Props
### `
12345}>Next
);
ReactDOM.render(, document.getElementById('root'));
```
### Justified
The buttons are laid out horizontally in the button set and are equally wide.
```js
import { Button, ButtonGroup, VStack } from 'rsuite';
const ButtonGroupWithAppearance = ({ appearance }) => (
ChatContactDiscoverSetting
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Icons
Use icons within button groups for better visual hierarchy and recognition.
```js
import { Button, ButtonToolbar, ButtonGroup } from 'rsuite';
import {
FaItalic,
FaBold,
FaUnderline,
FaStrikethrough,
FaAlignLeft,
FaAlignRight,
FaAlignCenter,
FaAlignJustify
} from 'react-icons/fa6';
const App = () => (
} toggleable />
} toggleable />
} toggleable />
} toggleable />
} toggleable />
} toggleable />
} toggleable />
} toggleable />
);
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA Properties
- ButtonGroup has a `group` role.
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------------- | ------------------------------------------------------------------------------------------ |
| block | boolean | Display the button group as a full-width block element spanning the entire container width |
| classPrefix | string `('btn-group')` | Custom CSS class prefix for styling flexibility and theme customization |
| disabled | boolean | Disable all buttons within the group |
| divided | boolean | Display buttons in a divided layout |
| justified | boolean | Distribute buttons evenly with equal width in horizontal layout |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | Uniform size for all buttons in the group (large/medium/small/extra-small) |
| vertical | boolean | Display buttons in a vertical stacked layout |
### ``
Extends the [`Stack`][stack] component.
[stack]: /components/stack
================================================================================
# Components: Calendar - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/calendar/en-US/index.md
================================================================================
# Calendar
A component that displays data by calendar
## Import
**Main import:**
```js
import { Calendar } from 'rsuite';
```
**Individual import:**
```js
import Calendar from 'rsuite/Calendar';
// (Optional) Import component styles.
import 'rsuite/Calendar/styles/index.css';
```
## Examples
### Basic
```js
import { Calendar } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Compact
```js
import { Calendar, Badge, List, HStack } from 'rsuite';
function getTodoList(date) {
if (!date) {
return [];
}
const day = date.getDate();
switch (day) {
case 10:
return [
{ time: '10:30 am', title: 'Meeting' },
{ time: '12:00 pm', title: 'Lunch' }
];
case 15:
return [
{ time: '09:30 pm', title: 'Products Introduction Meeting' },
{ time: '12:30 pm', title: 'Client entertaining' },
{ time: '02:00 pm', title: 'Product design discussion' },
{ time: '05:00 pm', title: 'Product test and acceptance' },
{ time: '06:30 pm', title: 'Reporting' }
];
default:
return [];
}
}
function renderCell(date) {
const list = getTodoList(date);
if (list.length) {
return ;
}
return null;
}
const App = () => {
const [selectedDate, setSelectedDate] = React.useState(null);
const handleSelect = date => {
setSelectedDate(date);
};
return (
);
};
const TodoList = ({ date }) => {
const list = getTodoList(date);
if (!list.length) {
return null;
}
return (
{list.map(item => (
{item.time}
{item.title}
))}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Custom cell styles
Use `cellClassName` function to specify the custom class name added to each cell. For example, in the following code, we specify that the `.bg-gray` class name is added on Monday, Wednesday, and Friday, so that the background color of the cells in these three columns is gray.
```js
import { Calendar } from 'rsuite';
const App = () => {
return (
<>
(date.getDay() % 2 ? 'bg-gray' : undefined)} />
>
);
};
const Styles = () => {
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Custom week
```js
import { Calendar, SegmentedControl, Toggle, VStack, HStack, Divider } from 'rsuite';
const options = [
{ value: 0, label: 'Sun' },
{ value: 1, label: 'Mon' },
{ value: 2, label: 'Tue' },
{ value: 3, label: 'Wed' },
{ value: 4, label: 'Thu' },
{ value: 5, label: 'Fri' },
{ value: 6, label: 'Sat' }
];
const App = () => {
const [weekStart, setWeekStart] = React.useState(0);
const [isoWeek, setIsoWeek] = React.useState(false);
const [showWeekNumbers, setShowWeekNumbers] = React.useState(true);
return (
} spacing={10}>
ISO week
Show week numbers
);
};
ReactDOM.render(, document.getElementById('root'));
```
- Use `weekStart` to specify the first day of the week. If `isoWeek` is set, this property is ignored.
- Use `isoWeek` to enable the [ISO 8601 standard][ISO-8601], where each calendar week begins on Monday and Sunday on the seventh day.
- Use `showWeekNumbers` to display week numbers.
### Lunar
```js
import { Calendar, Text, Badge, HStack, VStack } from 'rsuite';
import { HolidayUtil, Lunar, Solar } from 'lunar-typescript';
function renderCell(date) {
const lunar = Lunar.fromDate(date);
const jieqi = lunar.getJieQi();
const day = lunar.getDayInChinese();
return (
{jieqi || day}
);
}
const App = () => {
const [date, setDate] = React.useState(new Date());
const lunar = Lunar.fromDate(date);
const solar = Solar.fromDate(date);
const holiday = HolidayUtil.getHoliday(date.getFullYear(), date.getMonth() + 1, date.getDate());
return (
} spacing={10} wrap>
);
};
ReactDOM.render(, document.getElementById('root'));
function DayView({ date }) {
const lunar = Lunar.fromDate(date);
const solar = Solar.fromDate(date);
const holiday = HolidayUtil.getHoliday(date.getFullYear(), date.getMonth() + 1, date.getDate());
return (
{lunar.toString()}{holiday?.getName()}
{lunar.getYearInGanZhi()}({lunar.getYearShengXiao()})年
{solar.getXingZuo()}座
宜
{lunar.getDayYi()?.map(t => (
{t}
))}
忌
{lunar.getDayJi()?.map(t => (
{t}
))}
);
}
const HolidayStatus = ({ date }) => {
const holiday = HolidayUtil.getHoliday(date.getFullYear(), date.getMonth() + 1, date.getDate());
const styles = {
position: 'absolute',
right: -6,
top: -26,
transform: 'scale(0.8)',
padding: '0 2px'
};
const work = holiday?.isWork();
return holiday ? (
) : null;
};
```
## Props
### ``
| Property | Type | Description | Version |
| ------------------ | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| bordered | boolean | Show border | |
| cellClassName | (date: Date) => string \| undefined | Custom cell classes base on it's date | |
| compact | boolean | Display a compact calendar | |
| defaultValue | Date | The default value (uncontrolled) | |
| isoWeek | boolean | [ISO 8601 standard][ISO-8601], each calendar week begins on Monday and Sunday on the seventh day | |
| locale | [DateTimeFormats](/guide/i18n/#date-time-formats) | Locale configuration | |
| monthDropdownProps | [MonthDropdownProps][month-dropdown-props] | Props for the month dropdown | |
| onChange | (date: Date) => void | Callback fired before the value changed | |
| onSelect | (date: Date) => void | Callback fired before the date selected | |
| renderCell | (date: Date) => ReactNode | Custom render calendar cells | |
| value | Date | The current value (controlled) | |
| weekStart | 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 `(0)` | The index of the first day of the week (0 - Sunday). If `isoWeek` is `true`, the value of `weekStart` is ignored | ![][5.62.0] |
#### `ts:MonthDropdownProps`
```ts
import type { FixedSizeListProps } from 'react-window';
interface MonthDropdownProps extends Partial {
/**
* The HTML element or React component to render as the root element of the MonthDropdown.
*/
as?: React.ElementType;
/**
* The HTML element or React component to render as each item in the MonthDropdown.
*/
itemAs?: React.ElementType;
/**
* The CSS class name to apply to each item in the MonthDropdown.
*/
itemClassName?: string;
}
```
[month-dropdown-props]: #code-ts-month-dropdown-props-code
[ISO-8601]: https://en.wikipedia.org/wiki/ISO_week_date
================================================================================
# Components: Card - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/card/en-US/index.md
================================================================================
# Card
Card is a container component for displaying data, which can contain multiple child components such as images, buttons, and text. It is used to display information in a structured way.
## Import
**Main import:**
```js
import { Card, CardGroup } from 'rsuite';
```
**Individual import:**
```js
import Card from 'rsuite/Card';
import CardGroup from 'rsuite/CardGroup';
// (Optional) Import component styles.
import 'rsuite/Card/styles/index.css';
import 'rsuite/CardGroup/styles/index.css';
```
## Examples
### Basic
```js
import { Card, Text } from 'rsuite';
const App = () => {
return (
John Doe
A passionate developer with a love for learning new technologies. Enjoys building innovative
solutions and solving problems.
Joined in January 2023
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Shadow
```js
import { Card, Text } from 'rsuite';
const App = () => {
return (
John Doe
A passionate developer with a love for learning new technologies. Enjoys building innovative
solutions and solving problems.
Joined in January 2023
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Hover Shadow
```js
import { Card, Text } from 'rsuite';
const App = () => {
return (
John Doe
A passionate developer with a love for learning new technologies. Enjoys building innovative
solutions and solving problems.
Joined in January 2023
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Sizes
```js
import { Card, CardGroup, VStack } from 'rsuite';
const App = () => {
return (
Card Header - Small
This is a small card with a brief description to highlight key information or content. It
can be used for various purposes like displaying details, statistics, or any relevant
content.
Card Header - Medium
This is a medium card with a brief description to highlight key information or content. It
can be used for various purposes like displaying details, statistics, or any relevant
content.
Card Header - Large
This is a large card with a brief description to highlight key information or content. It
can be used for various purposes like displaying details, statistics, or any relevant
content.
);
};
ReactDOM.render(, document.getElementById('root'));
```
### With Avatar
```js
import { Card, Text, Avatar, HStack } from 'rsuite';
const App = () => {
return (
John Doe
Software Engineer
A passionate developer with a love for learning new technologies. Enjoys building innovative
solutions and solving problems.
Joined in January 2023
);
};
ReactDOM.render(, document.getElementById('root'));
```
### With Image
```js
import { Card, Text, Button, TagGroup, Tag } from 'rsuite';
const App = () => {
return (
Shadow
Meet Shadow, a spirited little explorer with a heart full of adventure! This charming pup
loves to roam the fields, soaking up the sights and sounds of nature.
🐶 Dog☀️ Sunny🌈 Rainbow
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Horizontal
```js
import { Card, Text, VStack, TagGroup, Tag } from 'rsuite';
const App = () => {
return (
Cream
Meet Shadow, a spirited little explorer with a heart full of adventure! This charming pup
loves to roam the fields, soaking up the sights and sounds of nature.
🐶 Dog☀️ Sunny🌈 Rainbow
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Placeholder
```js
import { Card, Placeholder } from 'rsuite';
const App = () => {
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Within Form
```js
import { Card, Heading, Text, Form, Button, SelectPicker } from 'rsuite';
const App = () => {
return (
Create projectFill in the form below to create a new projectNamePlatform
Create
Cancel
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Card Group
```js
import { Card, CardGroup, Text } from 'rsuite';
const items = [
{
name: 'John Doe',
avatar: 'https://i.pravatar.cc/150?u=9',
job: 'Software Engineer',
description:
'A passionate developer with a love for learning new technologies. Enjoys building innovative solutions and solving problems.',
joined: 'Joined in January 2023'
},
{
name: 'Jane Smith',
avatar: 'https://i.pravatar.cc/150?u=8',
job: 'UI/UX Designer',
description:
'A creative designer with a keen eye for aesthetics. Focuses on user experience and intuitive interfaces.',
joined: 'Joined in March 2022'
},
{
name: 'Michael Johnson',
avatar: 'https://i.pravatar.cc/150?u=7',
job: 'Data Scientist',
description:
'A data scientist who enjoys analyzing complex datasets and uncovering insights to drive business decisions.',
joined: 'Joined in June 2021'
},
{
name: 'Emily Davis',
avatar: 'https://i.pravatar.cc/150?u=6',
job: 'Project Manager',
description:
'A project manager with a passion for leading teams to success. Specializes in Agile methodologies and team coordination.',
joined: 'Joined in August 2020'
}
];
const App = () => {
const [columns, setColumns] = React.useState(2);
const [spacing, setSpacing] = React.useState(20);
return (
<>
{items.map((item, index) => (
{item.name}
{item.job}
{item.description}{item.joined}
))}
({ label: `${value} Columns`, value }))}
value={columns}
onChange={setColumns}
cleanable={false}
/>
({ label: `${value}px`, value }))}
value={spacing}
onChange={setSpacing}
cleanable={false}
/>
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(Default)` | Description |
| ----------- | -------------------- | -------------------------------------- |
| as | ElementType `(div)` | HTML tag of the component |
| bordered | boolean`(true)` | Whether the card has a border |
| children | ReactNode | The children of the component |
| classPrefix | string `('card')` | The prefix of the component class name |
| direction | 'row' \| 'column' | The direction of the card |
| shaded | boolean \| 'hover' | Whether there is a shadow |
| size | 'sm' \| 'md' \| 'lg' | The size of the card |
| width | string \| number | The width of the card |
### ``
| Property | Type`(Default)` | Description |
| ----------- | ------------------------ | -------------------------------------- |
| as | ElementType `(div)` | HTML tag of the component |
| classPrefix | string `('card-header')` | The prefix of the component class name |
| children | ReactNode | The children of the component |
### ``
| Property | Type`(Default)` | Description |
| ----------- | ---------------------- | -------------------------------------- |
| as | ElementType `(div)` | HTML tag of the component |
| classPrefix | string `('card-body')` | The prefix of the component class name |
| children | ReactNode | The children of the component |
### ``
| Property | Type`(Default)` | Description |
| ----------- | ------------------------ | -------------------------------------- |
| as | ElementType `(div)` | HTML tag of the component |
| classPrefix | string `('card-footer')` | The prefix of the component class name |
| children | ReactNode | The children of the component |
### ``
| Property | Type`(Default)` | Description |
| ----------- | ----------------------- | -------------------------------------- |
| as | ElementType `(div)` | HTML tag of the component |
| classPrefix | string `('card-group')` | The prefix of the component class name |
| children | ReactNode | The children of the component |
| columns | number | The number of columns of the group |
| spacing | number `(16)` | The spacing between the stats |
================================================================================
# Components: Carousel - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/carousel/en-US/index.md
================================================================================
# Carousel
Display a set of elements in a carousel
## Import
**Main import:**
```js
import { Carousel } from 'rsuite';
```
**Individual import:**
```js
import Carousel from 'rsuite/Carousel';
// (Optional) Import component styles.
import 'rsuite/Carousel/styles/index.css';
```
## Examples
### Basic
A basic carousel containing 5 images that can be navigated using the bottom indicators.
```js
import { Carousel } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled slides
Control the current slide programmatically using the `activeIndex` and `onSelect` props for a fully controlled carousel.
```js
import { Carousel } from 'rsuite';
const App = () => {
const [activeIndex, setActiveIndex] = React.useState(2);
return (
{
setActiveIndex(index);
}}
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
Customize the carousel's indicator position (top, bottom, left, right) and shape (dots or bars).
```js
import { Carousel, SegmentedControl, Divider, Text } from 'rsuite';
function App() {
const [placement, setPlacement] = React.useState('bottom');
const [shape, setShape] = React.useState('dot');
return (
<>
>
);
}
ReactDOM.render(, document.getElementById('root'));
```
### Autoplay
Enable automatic slide transitions without user interaction by setting the `autoplay` prop.
```js
import { Carousel } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------------ | ------------------------------------------------ | ---------------------------------------------- |
| activeIndex | number | Controls the current visible slide |
| as | ElementType `('div')` | Custom element type |
| autoplay | boolean | Automatic carousel element. |
| autoplayInterval | number (`4000`) | Delay in ms until navigating to the next item. |
| children | ReactNode | Carousel elements |
| classPrefix | string `('carousel')` | Component CSS class prefix |
| defaultActiveIndex | number (`0`) | The default initial slide |
| onSelect | (index: number, event?: ChangeEvent) => void | Callback fired when the active item changes |
| onSlideEnd | (index: number, event?: TransitionEvent) => void | Callback fired when a slide transition ends |
| onSlideStart | (index: number, event?: ChangeEvent) => void | Callback fired when a slide transition starts |
| placement | enum:'top','bottom','left','right' `('bottom')` | Button placement |
| shape | enum:'dot','bar' `('dot')` | Button shape |
================================================================================
# Components: Cascade Tree - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/cascade-tree/en-US/index.md
================================================================================
# CascadeTree
CascadeTree is a component that displays tree-structured data in columns.
## Import
**Main import:**
```js
import { CascadeTree } from 'rsuite';
```
**Individual import:**
```js
import CascadeTree from 'rsuite/CascadeTree';
// (Optional) Import component styles.
import 'rsuite/CascadeTree/styles/index.css';
```
## Examples
### Basic
```js
import { CascadeTree } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
return (
<>
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Custom options
```js
import { CascadeTree } from 'rsuite';
import AdminIcon from '@rsuite/icons/Admin';
import { mockTreeData } from './mock';
const headers = ['Job Area', 'Job Type', 'Name'];
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const Column = ({ header, children }) => {
return (
{header}
{children}
);
};
const App = () => (
{
return (
<>
{label}
>
);
}}
renderColumn={(childNodes, { layer }) => {
return {childNodes};
}}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Async Data
This tree allows the use of the `getChildren` option and the length of the children field on the node to be 0 to load children asynchronously.
```js
import { CascadeTree } from 'rsuite';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import PageIcon from '@rsuite/icons/Page';
import { mockAsyncData } from './mock';
const [getNodes, fetchNodes] = mockAsyncData();
const initialData = getNodes(5);
const App = () => {
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
```js
import { Cascader } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
const [value, setValue] = React.useState('1-2-2');
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
## Accessibility
### ARIA properties
- Cascader has role `combobox`.
- Has the `aria-haspopup="tree"` attribute to indicate that the combobox has a popup tree.
- Has the `aria-expanded` attribute to indicate whether the tree is open or not.
- Has the `aria-controls` attribute to indicate the ID of the tree element.
- Has the `aria-activedescendant` attribute to indicate the ID of the focused tree node.
- When `label` is set, the `aria-labelledby` attribute is added to the combobox element and the tree element and is set to the value of the `id` attribute of `label`.
### Keyboard interactions
- ↓ - Move focus to the next tree node.
- ↑ - Move focus to the previous tree node.
- → - Expand the focused tree node if it is collapsed.
- ← - Collapse the focused tree node if it is expanded.
- Enter - Select the focused tree node.
- Esc - Close the tree.
## Props
### ``
| Property | Type`(Default)` | Description |
| ------------------ | --------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| appearance | 'default' \| 'subtle' `('default')` | Set picker appearance |
| block | boolean | Occupy the full width of the parent container |
| caretAs | ElementType | Custom component for the caret icon |
| childrenKey | string `('children')` | Set children key in data |
| classPrefix | string `('picker')` | The prefix of the component CSS class |
| cleanable | boolean `(true)` | Whether the selected value can be cleared |
| columnHeight | number | Sets the height of the column |
| columnWidth | number | Sets the width of the column |
| container | HTMLElement \| (() => HTMLElement) | Sets the rendering container |
| data \* | [Option][item][] | The data of component |
| defaultValue | string | Default values of the selected items |
| disabled | boolean | Whether to disable the component |
| disabledItemValues | string[] | Values of disabled items |
| getChildren | (item: [Option][item]) => Promise<[Option][item][]> | Asynchronously load the children of the tree node |
| height | number `(320)` | The height of Dropdown |
| labelKey | string `('label')` | Set label key in data |
| loading | boolean `(false)` | Whether to display a loading state indicator |
| locale | [PickerLocaleType](/guide/i18n/#pickers) | Locale text settings |
| onChange | (value:string, event) => void | Callback fired when value changes |
| onClean | (event) => void | Callback fired when value is cleared |
| onClose | () => void | Callback fired when component closes |
| onEnter | () => void | Callback fired before the overlay transitions in |
| onEntered | () => void | Callback fired after the overlay finishes transitioning in |
| onEntering | () => void | Callback fired as the overlay begins to transition in |
| onExit | () => void | Callback fired right before the overlay transitions out |
| onExited | () => void | Callback fired after the overlay finishes transitioning out |
| onExiting | () => void | Callback fired as the overlay begins to transition out |
| onOpen | () => void | Callback fired when component opens |
| onSearch | (search:string, event) => void | Callback function for search |
| onSelect | (item: [Option][item], selectedPaths: [Option][item][], event) => void | Callback fired when an item is selected |
| open | boolean | Whether the component is open |
| parentSelectable | boolean | Whether parent nodes are selectable |
| placeholder | ReactNode `('Select')` | Placeholder text |
| placement | [Placement](#code-ts-placement-code) `('bottomStart')` | The placement of component |
| popupClassName | string | Custom CSS class for the popup |
| popupStyle | CSSProperties | Custom style for the popup |
| preventOverflow | boolean | Prevent floating element overflow |
| renderColumn | (childNodes: ReactNode, column: { items, parentItem, layer}) => ReactNode | Custom render function for column list |
| renderExtraFooter | () => ReactNode | Custom render function for extra footer |
| renderSearchItem | (node: ReactNode, items: [Option][item][]) => ReactNode | Custom render function for search result items |
| renderTreeNode | (node: ReactNode, item: [Option][item]) => ReactNode | Custom render function for tree nodes |
| renderValue | (value: string, selectedPaths: [Option][item][], selected:ReactNode) => ReactNode | Custom render function for selected items |
| searchable | boolean `(true)` | Whether the component is searchable |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | Size of the component |
| toggleAs | ElementType `('a')` | Custom element for the component |
| value | string | Value of the component (Controlled) |
| valueKey | string `('value')` | Set value key in data |
#### `ts:Option`
```ts
interface Option {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: V;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/**
* The data of the child option corresponds to the `childrenKey` in the data.
* Properties owned by tree structure components, such as TreePicker, Cascader.
*/
children?: Option[];
/**
* Properties of grouping functional components, such as CheckPicker, InputPicker
*/
groupBy?: string;
/**
* The children under the current node are loading.
* Used for components that have cascading relationships and lazy loading of children. E.g. Cascader, MultiCascader
*/
loading?: boolean;
}
```
#### `ts:Placement`
```ts
type Placement = 'bottomStart' | 'topStart' | 'autoVerticalStart';
```
[item]: #code-ts-option-code
================================================================================
# Components: Center - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/center/en-US/index.md
================================================================================
# Center
Center is a layout component that centers its child elements within itself.
## Import
**Main import:**
```js
import { Center } from 'rsuite';
```
**Individual import:**
```js
import Center from 'rsuite/Center';
// (Optional) Import component styles.
import 'rsuite/Center/styles/index.css';
```
## Examples
### Centered Content
```js
import { Center } from 'rsuite';
const App = () => (
This is centered content
);
ReactDOM.render(, document.getElementById('root'));
```
### Center with Inline
```js
import { Center, Box } from 'rsuite';
import { MdEmail } from 'react-icons/md';
const App = () => (
Send email
);
ReactDOM.render(, document.getElementById('root'));
```
### Icon
```js
import { Center, HStack } from 'rsuite';
import { MdEmail } from 'react-icons/md';
const App = () => (
(
0 && value.length < allValue.length}
checked={value.length === allValue.length}
onChange={handleCheckAll}
>
Check all
{
picker.current.close();
}}
>
Ok
)}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Async
```js
import { CheckPicker, HStack, Loader } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => {
const [items, setItems] = React.useState([]);
const updateData = () => {
setTimeout(() => {
if (items.length === 0) {
setItems(data);
}
}, 2000);
};
const renderListbox = listbox => {
if (items.length === 0) {
return (
);
}
return listbox;
};
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
```js
import { CheckPicker, RadioGroup, Radio } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => {
const [value, setValue] = React.useState([]);
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Virtualize Long Lists
```js
import { CheckPicker } from 'rsuite';
const data = Array.from({ length: 10000 }).map((_, index) => {
return {
label: `Item ${index} is a long text, Used to test the virtualized list.`,
value: `Item ${index}`
};
});
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
## Accessibility
### ARIA properties
- CheckPicker has role `combobox`.
- Has the `aria-haspopup="listbox"` attribute to indicate that the combobox has a popup listbox.
- Has the `aria-expanded` attribute to indicate whether the listbox is open or not.
- Has the `aria-controls` attribute to indicate the ID of the listbox element.
- Has the `aria-activedescendant` attribute to indicate the ID of the focused option.
- When `label` is set, the `aria-labelledby` attribute is added to the combobox element and the listbox element and is set to the value of the `id` attribute of `label`.
- listbox has the `aria-multiselectable=true` attribute to indicate that the listbox is multi-selectable.
### Keyboard interactions
- ↓ - Move focus to the next option.
- ↑ - Move focus to the previous option.
- Enter - Select the focused option.
- Esc - Close the listbox.
## Props
### ``
| Property | Type`(Default)` | Description |
| ------------------ | --------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| appearance | 'default' \| 'subtle' `('default')` | Set picker appearence |
| block | boolean | Whether to display the component as a block |
| caretAs | ElementType | Custom component for the caret icon |
| classPrefix | string `('picker')` | The prefix for the component CSS class |
| cleanable | boolean `(true)` | Whether the selected value can be cleared |
| container | HTMLElement \| (() => HTMLElement) | Sets the rendering container |
| countable | boolean `(true)` | Whether to display the count of selected items |
| data \* | [Option][item][] | The data for the component |
| defaultValue | [Value][value] | Default values of the selected items |
| disabled | boolean | Whether the component is disabled |
| disabledItemValues | [Value][value] | Values of items to be disabled |
| groupBy | string | Key for grouping data items |
| label | ReactNode | Label displayed at the beginning of the toggle button |
| labelKey | string `('label')` | Key for the label in the data items |
| listboxMaxHeight | number `(320)` | Maximum height of the listbox |
| listProps | [ListProps][listprops] | Properties for virtualized lists |
| loading | boolean `(false)` | Whether to display a loading state indicator |
| locale | [PickerLocaleType](/guide/i18n/#pickers) | Localization settings for component text |
| onChange | (value: [Value][value], event) => void | Callback fired when value changes |
| onClean | (event) => void | Callback fired when value is cleared |
| onClose | () => void | Callback fired when component closes |
| onEnter | () => void | Callback fired before the overlay transitions in |
| onEntered | () => void | Callback fired after the overlay finishes transitioning in |
| onEntering | () => void | Callback fired as the overlay begins to transition in |
| onExit | () => void | Callback fired right before the overlay transitions out |
| onExited | () => void | Callback fired after the overlay finishes transitioning out |
| onExiting | () => void | Callback fired as the overlay begins to transition out |
| onGroupTitleClick | (event) => void | Callback fired when a group title is clicked |
| onOpen | () => void | Callback fired when component opens |
| onSearch | (search:string, event) => void | Callback fired when search is performed |
| onSelect | (value: [Value][value], item: [Option][item] , event) => void | Callback fired when an item is selected |
| open | boolean | Whether the component is open |
| placeholder | ReactNode `('Select')` | Placeholder text |
| placement | [Placement](#code-ts-placement-code)`('bottomStart')` | The placement of the component |
| popupClassName | string | Custom class name for the popup |
| popupStyle | CSSProperties | Custom style for the popup |
| preventOverflow | boolean | Prevent floating element overflow |
| renderExtraFooter | () => ReactNode | Custom render function for extra footer |
| renderListbox | (listbox:ReactNode) => ReactNode | Custom render function for listbox |
| renderOption | (label: ReactNode, item:[Option][item]) => ReactNode | Custom render function for options |
| renderOptionGroup | (title: ReactNode, item:[Option][item]) => ReactNode | Custom render function for option groups |
| renderValue | (value: [Value][value], items: [Option][item][], selected:ReactNode) => ReactNode | Custom render function for selected items |
| searchable | boolean `(true)` | Whether to display search input box |
| searchBy | (keyword: string, label: ReactNode, item: Option) => boolean | Custom search function |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | Size of the picker |
| sort | (isGroup: boolean) => (a: any, b: any) => number | Custom sort function for options |
| sticky | boolean | Whether to stick selected options at the top |
| toggleAs | ElementType `('a')` | Custom element type for the component |
| value | [Value][value] | Values of the selected items (Controlled) |
| valueKey | string `('value')` | Key for the value in the data items |
| virtualized | boolean | Whether to use virtualized list |
#### `ts:Option`
```ts
interface Option {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: V;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/**
* The data of the child option corresponds to the `childrenKey` in the data.
* Properties owned by tree structure components, such as TreePicker, Cascader.
*/
children?: Option[];
/**
* Properties of grouping functional components, such as CheckPicker, InputPicker
*/
groupBy?: string;
/**
* The children under the current node are loading.
* Used for components that have cascading relationships and lazy loading of children. E.g. Cascader, MultiCascader
*/
loading?: boolean;
}
```
#### `ts:Placement`
```ts
type Placement =
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd'
| 'auto'
| 'autoVerticalStart'
| 'autoVerticalEnd'
| 'autoHorizontalStart'
| 'autoHorizontalEnd';
```
#### `ts:ListProps`
```ts
interface ListProps {
/**
* Size of a item in the direction being windowed.
*/
itemSize?: number | ((index: number) => number);
/**
* Scroll offset for initial render.
*/
initialScrollOffset?: number;
/**
* Called when the items rendered by the list change.
*/
onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
/**
* Called when the list scroll positions changes, as a result of user scrolling or scroll-to method calls.
*/
onScroll?: (props: ListOnScrollProps) => void;
}
```
### `ts:Value`
```ts
type Value = (string | number)[];
```
[item]: #code-ts-option-code
[value]: #code-ts-value-code
[listprops]: #code-ts-list-props-code
================================================================================
# Components: Check Tree - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/check-tree/en-US/index.md
================================================================================
# CheckTree
`` is used to display a tree structure data and supports Checkbox selection.
## Import
**Main import:**
```js
import { CheckTree } from 'rsuite';
```
**Individual import:**
```js
import CheckTree from 'rsuite/CheckTree';
// (Optional) Import component styles.
import 'rsuite/CheckTree/styles/index.css';
```
## Examples
### Basic
```js
import { CheckTree } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Cascade
The cascade attribute can set whether or not CheckTree can consider the cascade relationship of the parent parent when selecting. The default value is true.
```js
import { CheckTree } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
const [cascade, setCascade] = React.useState(false);
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Asynchronous Loading of Child Nodes
```js
import { CheckTree } from 'rsuite';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import PageIcon from '@rsuite/icons/Page';
import { mockAsyncData } from './mock';
const [getNodes, fetchNodes] = mockAsyncData();
const data = getNodes(5);
const TreeNode = ({ children, ...rest }) => {
return (
{children}
);
};
const App = () => {
const [value, setValue] = React.useState([]);
return (
setValue(value)}
getChildren={fetchNodes}
renderTreeNode={node => {
return (
{node.children ? : } {node.label}
);
}}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Searchable
```js
import { CheckTree } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Uncheckable Tree Node
```js
import { CheckTree } from 'rsuite';
const data = [
{
label: 'Node 1',
value: '1'
},
{
label: 'Node 2',
value: '2',
children: [
{
label: 'Node 2-1',
value: '2-1',
children: [
{
label: 'Node 2-1-1',
value: '2-1-1'
},
{
label: 'Node 2-1-2',
value: '2-1-2'
}
]
},
{
label: 'Node 2-2',
value: '2-2'
}
]
}
];
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled Tree Node
```js
import { CheckTree } from 'rsuite';
const data = [
{
label: 'Node 1',
value: '1',
children: [
{
label: 'Node 1-1',
value: '1-1'
},
{
label: 'Node 1-2',
value: '1-2'
}
]
},
{
label: 'Node 2',
value: '2',
children: [
{
label: 'Node 2-1',
value: '2-1',
children: [
{
label: 'Node 2-1-1',
value: '2-1-1'
},
{
label: 'Node 2-1-2',
value: '2-1-2'
}
]
},
{
label: 'Node 2-2',
value: '2-2'
}
]
}
];
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Scroll Shadows
```js
import { CheckTree } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
**tree**
- CheckTree has role `tree`.
- CheckTree has the `aria-multiselectable=true` attribute to indicate that the tree is multi-selectable.
**treeitem**
- CheckTree node has role `treeitem`.
- Has the `aria-expanded` attribute to indicate whether the tree is open or not.
- Has the `aria-checked` attribute to indicate whether the tree node is checked or not.
- Has the `aria-level` attribute to indicate the level of the tree node.
- Has the `aria-disabled` attribute to indicate whether the tree node is disabled or not.
### Keyboard interactions
- ↓ - Move focus to the next tree node.
- ↑ - Move focus to the previous tree node.
- → - Expand the focused tree node if it is collapsed.
- ← - Collapse the focused tree node if it is expanded.
- Enter - Select the focused tree node.
## Props
### ``
| Property | Type `(Default)` | Description | Version |
| ----------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ----------- |
| cascade | boolean `(true)` | Whether to enable cascade selection | |
| childrenKey | string `('children')` | Set the `key` of the child node of the tree node in `data` | |
| data \* | [TreeNode][node][] | Data to render the tree | |
| defaultExpandAll | boolean | Default expand all nodes | |
| defaultExpandItemValues | string[] | Set the value of the default expanded node | |
| defaultValue | string[] | Default selected Value | |
| disabledItemValues | string[] | Disabled tree node values | |
| expandItemValues | string[] | Set the value of the expanded node (controlled) | |
| getChildren | (item: [TreeNode][node]) => Promise<[TreeNode][node]> | Load node children data asynchronously | |
| height | number `(360px)` | The height of the tree | |
| labelKey | string `('label')` | Set the tree node display content to the `key` in `data` | |
| listProps | [ListProps][listprops] | Properties of virtualized lists | |
| onChange | (values:string[]) => void | Called when the tree value changes | |
| onExpand | (expandItemValues: string[], item: [TreeNode][node], concat:(data, children) => Array) => void | Called when the tree node expands the child node | |
| onSearch | (keyword: string) => void | Called when the search box changes | |
| onSelect | (item: [TreeNode][node], value:string, event) => void | Called when the tree node is selected | |
| renderTreeIcon | (item: [TreeNode][node], expanded: boolean) => ReactNode | Custom render the icon in tree node | |
| renderTreeNode | (item: [TreeNode][node]) => ReactNode | Custom render tree node | |
| scrollShadow | boolean | The shadow of the content when scrolling | ![][5.62.0] |
| searchable | boolean | Whether to show the search box | ![][5.61.0] |
| searchKeyword | string | Set search keywords for the search box | |
| uncheckableItemValues | string[] | Set the tree node values that do not display checkboxes | |
| value | string[] | The value of the selected tree node | |
| valueKey | string `('value')` | Set the `key` of the tree node value in `data` | |
| virtualized | boolean | Whether to enable virtualized lists | |
#### `ts:TreeNode`
```ts
interface TreeNode {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: string | number;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/** The data of the child option corresponds to the `childrenKey` in the data. */
children?: TreeNode[];
}
```
#### `ts:ListProps`
```ts
interface ListProps {
/**
* Size of a item in the direction being windowed.
*/
itemSize?: number | ((index: number) => number);
/**
* Scroll offset for initial render.
*/
initialScrollOffset?: number;
/**
* Called when the items rendered by the list change.
*/
onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
/**
* Called when the list scroll positions changes, as a result of user scrolling or scroll-to method calls.
*/
onScroll?: (props: ListOnScrollProps) => void;
}
```
## Related components
- [``](/components/tree)
- [``](/components/tree-picker)
- [``](/components/check-tree-picker)
[listprops]: #code-ts-list-props-code
[node]: #code-ts-tree-node-code
================================================================================
# Components: Check Tree Picker - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/check-tree-picker/en-US/index.md
================================================================================
# CheckTreePicker
CheckTreePicker are supported in multiple selectors for multiple selection of complex data structures.
## Import
**Main import:**
```js
import { CheckTreePicker } from 'rsuite';
```
**Individual import:**
```js
import CheckTreePicker from 'rsuite/CheckTreePicker';
// (Optional) Import component styles.
import 'rsuite/CheckTreePicker/styles/index.css';
```
## Examples
### Basic
```js
import { CheckTreePicker, VStack } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
```js
import { CheckTreePicker } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { CheckTreePicker, VStack } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Cascade
The cascade attribute can set whether or not CheckTreePicker can consider the cascade relationship of the parent parent when selecting. The default value is true.
```js
import { CheckTreePicker } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
const [cascade, setCascade] = React.useState(false);
return (
{
setCascade(checked);
}}
>
Cascade
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Show Indent Lines
```js
import { CheckTreePicker, VStack } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Placement and Prevent overflow
```js
import { CheckTreePicker } from 'rsuite';
import { mockTreeData } from './mock';
import PlacementContainer from '@/components/PlacementContainer';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
{({ container, placement, preventOverflow }) => (
)}
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import { CheckTreePicker, VStack, HStack, Text, Divider } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const Field = ({ label, children, ...rest }) => (
{label}
);
const App = () => (
}>
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom options
```js
import { CheckTreePicker, Button, HStack } from 'rsuite';
import PeoplesIcon from '@rsuite/icons/Peoples';
import AdminIcon from '@rsuite/icons/Admin';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [3, 3, 4],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => (
Select
}
renderTreeNode={nodeData => {
return (
{nodeData.label}
);
}}
renderValue={(value, checkedItems) => {
return (
Peoples:
{checkedItems.map(item => item.label).join(' , ')}
);
}}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Async
```js
import { CheckTreePicker, Loader, HStack } from 'rsuite';
import { mockAsyncData } from './mock';
const [getNodes, fetchNodes] = mockAsyncData();
const App = () => {
const [value, setValue] = React.useState([]);
const [data, setData] = React.useState([]);
return (
setValue(value)}
onOpen={() => {
if (data.length === 0) {
setTimeout(() => setData(getNodes(5)), 1000);
}
}}
renderTree={tree => {
if (data.length === 0) {
return (
);
}
return tree;
}}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Extra footer
```js
import { CheckTreePicker, Checkbox, HStack } from 'rsuite';
import { mockTreeData } from './mock';
const data = mockTreeData({
limits: [4, 6, 6],
labels: (layer, value, faker) => {
const methodName = ['jobArea', 'jobType', 'firstName'];
return faker.person[methodName[layer]]();
}
});
const App = () => {
const [value, setValue] = React.useState([]);
const handleCheckAll = (_v, checked) => {
if (checked) {
setValue(data.map(item => item.value));
} else {
setValue([]);
}
};
return (
(
Check all
)}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
## Accessibility
### ARIA properties
**combobox**
- CheckTreePicker has role `combobox`.
- Has the `aria-haspopup="tree"` attribute to indicate that the combobox has a popup tree.
- Has the `aria-controls` attribute to indicate the ID of the tree element.
- Has the `aria-activedescendant` attribute to indicate the ID of the focused tree node.
- When `label` is set, the `aria-labelledby` attribute is added to the combobox element and the tree element and is set to the value of the `id` attribute of `label`.
**tree**
- CheckTree has role `tree`.
- CheckTree has the `aria-multiselectable=true` attribute to indicate that the tree is multi-selectable.
**treeitem**
- CheckTree node has role `treeitem`.
- Has the `aria-expanded` attribute to indicate whether the tree is open or not.
- Has the `aria-checked` attribute to indicate whether the tree node is checked or not.
- Has the `aria-level` attribute to indicate the level of the tree node.
- Has the `aria-disabled` attribute to indicate whether the tree node is disabled or not.
### Keyboard interactions
- ↓ - Move focus to the next tree node.
- ↑ - Move focus to the previous tree node.
- → - Expand the focused tree node if it is collapsed.
- ← - Collapse the focused tree node if it is expanded.
- Enter - Select the focused tree node.
- Esc - Close the tree.
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| appearance | 'default' \| 'subtle' `('default')` | The appearance of the component |
| block | boolean | Whether to take up the full width of the parent container |
| caretAs | ElementType | Custom component for the caret icon |
| cascade | boolean | Whether to enable cascade selection |
| childrenKey | string `('children')` | Set the `key` of the child node of the tree node in `data` |
| cleanable | boolean `(true)` | Whether to display the clear button |
| container | HTMLElement \| (() => HTMLElement) | Specify the container for the popup |
| countable | boolean `(true)` | Whether to display the number of selected tree node |
| data \* | [TreeNode][node][] | Data to render the tree |
| defaultExpandAll | boolean | Default expand all nodes |
| defaultExpandItemValues | string[] | Set the value of the default expanded node |
| defaultValue | string[] | Default selected Value |
| disabled | boolean | Whether the component is disabled |
| disabledItemValues | string[] | Disabled tree node values |
| expandItemValues | string[] | Set the value of the expanded node (controlled) |
| getChildren | (item: [TreeNode][node]) => Promise<[TreeNode][node]> | Load node children data asynchronously |
| labelKey | string `('label')` | Set the tree node display content to the `key` in `data` |
| listProps | [ListProps][listprops] | Properties of virtualized lists |
| loading | boolean `(false)` | Whether the component is in a loading state |
| locale | [PickerLocaleType](/guide/i18n/#pickers) | Localization configuration |
| onCascadeChange | (values:string[], event:SyntheticEvent) => void | In the cascade case, the leaf node's value change callbacks |
| onChange | (values:string[]) => void | Called when the tree value changes |
| onClean | (event) => void | Called when the clear button is clicked |
| onClose | () => void | Called when the popup is closed |
| onEnter | () => void | Called when the popup is about to open |
| onEntered | () => void | Called when the popup is opened |
| onEntering | () => void | Called when popup opening is in progress |
| onExit | () => void | Called when the popup is about to close |
| onExited | () => void | Called when the popup is closed |
| onExiting | () => void | Called when popup closing is in progress |
| onExpand | (expandItemValues: string[], item: [TreeNode][node], concat:(data, children) => Array) => void | Called when the tree node expands the child node |
| onOpen | () => void | Called when the popup is opened |
| onSearch | (search:string, event) => void | Called when the search box input changes |
| onSelect | (item:[TreeNode][node], value:string, event) => void | Called when the tree node is selected |
| open | boolean | Whether the popup is displayed |
| placeholder | ReactNode `('Select')` | Placeholder content when there is no value |
| placement | [Placement](#code-ts-placement-code) `('bottomStart')` | The placement of the popup |
| popupClassName | string | Custom class name for the popup |
| popupStyle | CSSProperties | Custom style for the popup |
| preventOverflow | boolean | Prevent popup element overflow |
| renderExtraFooter | () => ReactNode | Custom render extra footer |
| renderTree | (tree:ReactNode) => ReactNode | Custom render tree |
| renderTreeIcon | (item:[TreeNode][node], expanded: boolean) => ReactNode | Custom render tree node icon |
| renderTreeNode | (item:[TreeNode][node]) => ReactNode | Custom render tree node |
| renderValue | (values:string[], checkedItems:[TreeNode][node][],selectedElement: ReactNode) => ReactNode | Custom render selected items |
| searchable | boolean `(true)` | Whether display search input box |
| searchBy | (keyword: string, label: ReactNode, item: [TreeNode][node]) => boolean | Custom search method |
| showIndentLine | boolean | Whether to show the indent line |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | The size of the component |
| toggleAs | ElementType `('a')` | Custom component for the toggle button |
| treeHeight | number `(320)` | The height of the tree |
| uncheckableItemValues | string[] | Set the tree node values that do not display checkboxes |
| value | string[] | Selected value |
| valueKey | string `('value')` | Set the `key` of the tree node value in `data` |
| virtualized | boolean | Whether to enable virtualized lists |
#### `ts:TreeNode`
```ts
interface TreeNode {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: string | number;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/** The data of the child option corresponds to the `childrenKey` in the data. */
children?: TreeNode[];
}
```
#### `ts:Placement`
```ts
type Placement =
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd'
| 'auto'
| 'autoVerticalStart'
| 'autoVerticalEnd'
| 'autoHorizontalStart'
| 'autoHorizontalEnd';
```
#### `ts:ListProps`
```ts
interface ListProps {
/**
* Size of a item in the direction being windowed.
*/
itemSize?: number | ((index: number) => number);
/**
* Scroll offset for initial render.
*/
initialScrollOffset?: number;
/**
* Called when the items rendered by the list change.
*/
onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
/**
* Called when the list scroll positions changes, as a result of user scrolling or scroll-to method calls.
*/
onScroll?: (props: ListOnScrollProps) => void;
}
```
## Related Components
- [``](/components/check-tree)
- [``](/components/tree)
- [``](/components/tree-picker)
[listprops]: #code-ts-list-props-code
[node]: #code-ts-tree-node-code
================================================================================
# Components: Checkbox - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/checkbox/en-US/index.md
================================================================================
# Checkbox
Check boxes are usually used in groups. Allow users to select one or more values from a set.
## Import
**Main import:**
```js
import { Checkbox, CheckboxGroup } from 'rsuite';
```
**Individual import:**
```js
import Checkbox from 'rsuite/Checkbox';
import CheckboxGroup from 'rsuite/CheckboxGroup';
// (Optional) Import component styles.
import 'rsuite/Checkbox/styles/index.css';
import 'rsuite/CheckboxGroup/styles/index.css';
```
## Examples
### Basic
```js
import { Checkbox, HStack } from 'rsuite';
const App = () => (
LabelChecked
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
Use the `disabled` prop to disable a checkbox or `readOnly` to make it read-only, preventing user interaction.
```js
import { Checkbox, HStack } from 'rsuite';
const App = () => (
<>
Default
Checked
Indeterminate
Default
Checked
Indeterminate
Default
Checked
Indeterminate
>
);
function Label({ children }) {
return (
);
}
ReactDOM.render(, document.getElementById('root'));
```
### Indeterminate
The `indeterminate` property sets the Checkbox to an indeterminate state, mainly used in the select all or tree structure Checkbox.
```js
import { Checkbox, CheckboxGroup, VStack } from 'rsuite';
const data = ['A', 'B'];
const App = () => {
const [value, setValue] = React.useState(['A']);
const handleCheckAll = (value, checked) => setValue(checked ? data : []);
const handleChange = value => setValue(value);
return (
0 && value.length < data.length}
checked={value.length === data.length}
onChange={handleCheckAll}
>
Parent Checkbox
{data.map(item => (
Child Checkbox {item}
))}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Colors
Customize checkbox colors using the `color` property. Supports preset theme colors.
```js
import { Checkbox, HStack } from 'rsuite';
const App = () => (
Red
Orange
Yellow
Green
Cyan
Blue
Violet
);
ReactDOM.render(, document.getElementById('root'));
```
### Checkbox Group
Use `` to manage a group of checkboxes. The `value` prop controls which options are selected.
```js
import { Checkbox, CheckboxGroup } from 'rsuite';
const App = () => (
Checkbox ACheckbox BCheckbox CCheckbox D
);
ReactDOM.render(, document.getElementById('root'));
```
### Inline Layout
Add the `inline` prop to `` to arrange checkboxes horizontally instead of vertically.
```js
import { Checkbox, CheckboxGroup } from 'rsuite';
const App = () => (
Checkbox ACheckbox BCheckbox CCheckbox D
);
ReactDOM.render(, document.getElementById('root'));
```
### Checkbox Group (Controlled)
Manage checkbox group state with the `value` and `onChange` props for controlled component behavior.
```js
import { Checkbox, CheckboxGroup } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState(['A', 'C']);
return (
{
setValue(value);
}}
>
Checkbox ACheckbox BCheckbox CCheckbox D
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- The `role` property of the CheckboxGroup is `group`.
- The `role` property of each Checkbox is `checkbox`.
- If the Checkbox is disabled, set `aria-disabled` to `true`.
- If the Checkbox is checked, set `aria-checked` to `true`, otherwise set it to `false`.
- When partially checked, it has state `aria-checked` set to mixed.
- A visible label referenced by the value of `aria-labelledby` set on the element with role `checkbox`.
### Keyboard interaction
- When the Checkbox has focus, pressing the Space key changes the state of the Checkbox.
## Props
### ``
| Property | Type `(default)` | Description | Version |
| -------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------- | ----------- |
| as | ElementType`(div)` | Custom element type for the component | |
| checked | boolean | Specifies whether the checkbox is selected | |
| color | [Color](#code-ts-color-code) | The color of the checkbox when checked or indeterminate | ![][5.56.0] |
| defaultChecked | boolean | Specifies the initial state: whether or not the checkbox is selected | |
| disabled | boolean | Whether disabled | |
| indeterminate | boolean | When being a checkbox , setting styles after the child part is selected | |
| inputRef | Ref | Ref of input element | |
| name | string | Used for the name of the form | |
| onChange | (value: string \| number, checked: boolean, event) => void | Callback fired when checkbox is triggered and state changes | |
| title | string | HTML title | |
| value | string \| number | Correspond to the value of CheckboxGroup, determine whether to select | |
### ``
| Property | Type `(default)` | Description |
| ------------ | ------------------------------------------- | ----------------------------------------------------------- |
| defaultValue | string[] \| number[] | The default value |
| inline | boolean | Inline layout |
| name | string | Used for the name of the form |
| onChange | (value:string[] \| number[], event) => void | Callback fired when checkbox is triggered and state changes |
| value | string[] \| number[] | Value of checked box (Controlled) |
### Type Definitions
#### `ts:Color`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
```
================================================================================
# Components: Custom Provider - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/custom-provider/en-US/index.md
================================================================================
# CustomProvider
Support personalized configurations such as localization, Right to Left, and themes.
## Import
**Main import:**
```js
import { CustomProvider } from 'rsuite';
```
**Individual import:**
```js
import CustomProvider from 'rsuite/CustomProvider';
```
## Usage
### Localization
```jsx
import zhCN from 'rsuite/locales/zh_CN';
return (
);
```
### Right to Left
```jsx
return (
);
```
### Themes
```jsx
return (
);
```
### Global Configuration of Default Values for Components
```jsx
const components = {
Button: {
defaultProps: { size: 'sm' }
},
Input: {
defaultProps: { size: 'sm' }
}
// more components...
};
return (
);
```
### Content Security Policy
The icon animations in `@rsuite/icons` use inline styles. If your project enables [Content Security Policy][csp], make sure to configure the [nonce][nonce] value.
```jsx
return (
);
```
## Props
### ``
| Property | Type`(Default)` | Description | Version |
| ------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------- | ----------- |
| components | [Components](#code-ts-components-code) | Custom component default configuration | ![][5.74.0] |
| csp | { nonce: string } | Configure the [nonce][nonce] value of [Content Security Policy][csp] | ![][5.73.0] |
| disableInlineStyles | boolean | Disable inline styles | ![][5.73.0] |
| disableRipple | boolean | If true, the ripple effect is disabled. Affected components include: `Button`, `Nav.Item`, `Pagination` | |
| formatDate | (date: Date, format?: string) => string | Return the formatted date string in the given format. The result may vary by locale. | |
| locale | [Locale][locale] [`(en-GB)`][en_gb] | Configure Language Pack | |
| parseDate | (date: string, format: string) => Date | Return the date parsed from string using the given format string. | |
| rtl | boolean | Text and other elements go from left to right. | |
| theme | 'light' \| 'dark' \| 'high-contrast' | Supported themes | |
#### `ts:Components`
```ts
import type { ButtonProps } from '../Button';
import type { InputProps } from '../Input';
interface ComponentProps {
defaultProps: Partial;
}
export interface Components {
Button: ComponentProps;
Input: ComponentProps;
// more components...
}
```
[nonce]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
[csp]: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
[en_gb]: https://github.com/rsuite/rsuite/blob/main/src/locales/en_GB.ts
[locale]: https://github.com/rsuite/rsuite/blob/main/src/locales/index.ts
================================================================================
# Components: Date Input - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/date-input/en-US/index.md
================================================================================
# DateInput
The DateInput component lets users select a date with the keyboard.
## Import
**Main import:**
```js
import { DateInput } from 'rsuite';
```
**Individual import:**
```js
import DateInput from 'rsuite/DateInput';
// (Optional) Import component styles.
import 'rsuite/DateInput/styles/index.css';
```
## Examples
### Basic
```js
import { DateInput } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Customize the date format
```js
import { DateInput, Stack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import { DateInput, InputGroup, HStack, VStack, Text, Divider } from 'rsuite';
import CalendarIcon from '@rsuite/icons/Calendar';
const App = () => (
}>
Disabled
ReadOnly
Plaintext
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled vs. uncontrolled value
```js
import { DateInput, Stack, Button } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState(new Date());
const handleChange = (value, event) => {
setValue(value);
console.log('Controlled Change', value);
};
return (
setValue(null)}>Clear
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- The DateInput component is the `` element.
- When the DateInput component is disabled, the `disabled` property is added to the `` element.
- When the DateInput component is read only, the `readonly` property is added to the `` element.
### Keyboard interactions
- Use →← keyboard to navigate to the previous or next date segment.
- Use ↓↑ keys to increase and decrease values.
- Use Backspace key to delete selected value.
- Use numeric key to update selected value.
## Props
### ``
| Property | Type`(default)` | Description |
| ------------ | ------------------------------- | --------------------------------------------------------- |
| defaultValue | Date | The default value (uncontrolled) |
| disabled | boolean | Whether disabled the component |
| format | string `('yyyy-MM-dd')` | Format of the date when rendered in the input |
| onChange | (date: Date, event) => void | Callback fired when value changed |
| plaintext | boolean | Whether plaintext the component |
| readOnly | boolean | Whether read only the component |
| size | 'lg'〡'md'〡'sm'〡'xs' `('md')` | Date input can have different sizes |
| value | Date | The selected value. Used when the component is controlled |
================================================================================
# Components: Date Picker - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/date-picker/en-US/index.md
================================================================================
# DatePicker
DatePicker is a highly customizable component that allows users to enter and pick dates and times in different formats.
## Usage
**Main import:**
```js
import { DatePicker } from 'rsuite';
```
**Individual import:**
```js
import DatePicker from 'rsuite/DatePicker';
// (Optional) Import component styles.
import 'rsuite/DatePicker/styles/index.css';
```
## Examples
### Basic
```js
import { DatePicker } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Customize the date format
```js
import { DatePicker, Stack } from 'rsuite';
import { FaCalendar, FaClock } from 'react-icons/fa';
import { BsCalendar2MonthFill } from 'react-icons/bs';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { DatePicker, Stack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### One tap
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Block
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Placeholder
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### ISO week
International Standard ISO 8601 defines that each calendar week begins on Monday and Sunday is the seventh day, [ISO week date](https://en.wikipedia.org/wiki/ISO_week_date).
The calendar panel can be displayed in ISO standard via the `isoWeek` property setting.
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Week start
The calendar panel can be displayed in different week start days via the `weekStart` property setting.
```js
import { DatePicker, SegmentedControl } from 'rsuite';
const options = [
{ value: 0, label: 'Sun' },
{ value: 1, label: 'Mon' },
{ value: 2, label: 'Tue' },
{ value: 3, label: 'Wed' },
{ value: 4, label: 'Thu' },
{ value: 5, label: 'Fri' },
{ value: 6, label: 'Sat' }
];
const App = () => {
const [weekStart, setWeekStart] = React.useState(0);
return (
<>
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Show week numbers
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import { DatePicker, VStack, HStack, Text, Divider } from 'rsuite';
import { isBefore } from 'date-fns/isBefore';
const Field = ({ label, children, ...rest }) => (
{label}
);
const App = () => (
}>
isBefore(date, new Date())}
/>
{
const month = date.getMonth();
return month === 0 || month === 11;
}}
format="yyyy-MM"
/>
hour < 8 || hour > 18}
shouldDisableMinute={minute => minute % 15 !== 0}
shouldDisableSecond={second => second % 30 !== 0}
/>
hour < 8 || hour > 18}
hideMinutes={minute => minute % 15 !== 0}
hideSeconds={second => second % 30 !== 0}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Loading state
```js
import { DatePicker, Stack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With a label
```js
import { DatePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Disable input
`DatePicker` allows date and time input via keyboard by default, if you wish to disable it, you can disable input by setting `editable={false}`.
```js
import { DatePicker, Stack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Set the local language
`DatePicker` supports local language custom configuration, but we recommend using the unified [i18n](/guide/i18n) configuration.
```js
import { DatePicker } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Placement and Prevent overflow
```js
import { DatePicker } from 'rsuite';
import PlacementContainer from '@/components/PlacementContainer';
const App = () => {
return (
{({ container, placement, preventOverflow }) => (
)}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Custom short options
Clicking "Prev Day" in the example does not close the picker layer because the `closeOverlay=false` property is configured. This property is used to set whether to close the picker layer after clicking the shortcut item. The default value is `true`.
```js
import { DatePicker, Stack } from 'rsuite';
import { addDays } from 'date-fns/addDays';
import { subDays } from 'date-fns/subDays';
const predefinedBottomRanges = [
{
label: 'today',
value: new Date()
},
{
label: 'Prev Day',
closeOverlay: false,
value: date => {
return subDays(date, 1);
}
}
];
const predefinedRanges = [
{
label: 'yesterday',
value: addDays(new Date(), -1),
placement: 'left'
},
{
label: 'today',
value: new Date(),
placement: 'left'
},
{
label: 'Prev Day',
closeOverlay: false,
value: date => {
return subDays(date, 1);
}
}
];
const App = () => (
{
console.log(shortcut);
}}
/>
{
console.log(shortcut);
}}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled vs. uncontrolled value
```js
import { DatePicker, Stack } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState(new Date());
const handleChange = (value, event) => {
setValue(value);
console.log('Controlled Change', value);
};
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Selection range
```js
import { DatePicker, InputGroup } from 'rsuite';
const App = () => (
to
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Calendar Icon
```js
import { DatePicker, Stack } from 'rsuite';
import {
FaCalendar,
FaCalendarWeek,
FaCalendarDay,
FaCalendarCheck,
FaClock
} from 'react-icons/fa';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Calendar Cell
```js
import { DatePicker } from 'rsuite';
const App = () => (
{
const day = date.getDate();
const month = date.getMonth();
const weekday = date.getDay();
if (day === 1 && month === 9) {
return {day}🎉;
}
if (month === 1 && day === 14) {
return {day}❤️;
}
if (weekday === 0 || weekday === 6) {
return {day};
}
return day;
}}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom render value
```js
import { DatePicker } from 'rsuite';
import { format } from 'date-fns/format';
const App = () => {
return (
<>
{
return format(value, 'EEE, d MMM');
}}
/>
{
return format(value, 'EEE, d MMM');
}}
/>
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Native pickers
If you only need to meet the simple date selection function, you can use the native pickers supported by the browser.
```js
import { VStack, Input, Text } from 'rsuite';
const App = () => (
type="date"type="datetime-local"type="week"type="time"
);
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
## Accessibility
### ARIA properties
Has all ARIA properties of the DateInput component by default.
- The `aria-invalid="true"` attribute is added to the `` element when the value is invalid.
- When `label` is set, the `aria-labelledby` attribute is added to the `` element and the `dialog` element and is set to the value of the `id` attribute of `label`.
- Has the `aria-haspopup="dialog"` attribute to indicate that the component has an interactive dialog.
### Keyboard interactions
Has keyboard interaction for the DateInput component by default.
- When the focus is on the calendar, use the →←↓↑ keys to switch dates.
- When the focus is on the calendar, use the Enter key to select a date.
- When the DatePicker component has `editable={false}` set to disable input, use ↓ to move focus to the calendar.
## Props
### ``
| Property | Type`(default)` | Description | Version |
| --------------------- | ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| appearance | 'default' \| 'subtle' `('default')` | Set picker appearence | |
| block | boolean | Blocking an entire row | |
| calendarDefaultDate | Date | Calendar panel default presentation date and time | |
| caretAs | ElementType | Custom component for the caret icon | |
| cleanable | boolean `(true)` | Whether the selected value can be cleared | |
| container | HTMLElement \| (() => HTMLElement) | Sets the rendering container | |
| defaultOpen | boolean | Default value of open property | |
| defaultValue | Date | The default value (uncontrolled) | |
| disabled | boolean | Whether disabled the component | |
| editable | boolean `(true)` | Rendered as an input, the date can be entered via the keyboard | |
| format | string `('dd/MM/yyyy')` | Format of the date when rendered in the input | |
| hideHours | (hour:number, date:Date) => boolean | Hide specific hour options | |
| hideMinutes | (minute:number, date:Date) => boolean | Hide specific minute options | |
| hideSeconds | (second:number, date:Date) => boolean | Hide specific second options | |
| isoWeek | boolean | [ISO 8601 standard][iso-8601], each calendar week begins on Monday and Sunday on the seventh day | |
| label | ReactNode | A label displayed at the beginning of toggle button | |
| limitEndYear | number `(1000)` | Set the upper limit of the available year relative to the current selection date | |
| limitStartYear | number | Set the lower limit of the available year relative to the current selection date | |
| loading | boolean `(false)` | Whether to display a loading state indicator | |
| locale | [DateTimeFormats](/guide/i18n/#date-time-formats) | Define localization settings to show component text in the user's regional language | |
| monthDropdownProps | [MonthDropdownProps][month-dropdown-props] | Props for the month dropdown | |
| onChange | (date: Date) => void | Callback fired when value changed | |
| onChangeCalendarDate | (date: Date, event) => void | Callback function that changes the calendar date. | |
| onClean | (event) => void | Callback fired when value clean | |
| onClose | () => void | Callback fired when close component | |
| onEnter | () => void | Callback fired before the overlay transitions in | |
| onEntered | () => void | Callback fired after the overlay finishes transitioning in | |
| onEntering | () => void | Callback fired as the overlay begins to transition in | |
| oneTap | boolean | One click to complete the selection date | |
| onExit | () => void | Callback fired right before the overlay transitions out | |
| onExited | () => void | Callback fired after the overlay finishes transitioning out | |
| onExiting | () => void | Callback fired as the overlay begins to transition out | |
| onNextMonth | (date: Date) => void | Switch to the callback function for the next Month | |
| onOk | (date: Date, event) => void | Click the OK callback function | |
| onOpen | () => void | Callback fired when open component | |
| onPrevMonth | (date: Date) => void | Switch to the callback function for the previous Month | |
| onSelect | (date: Date) => void | Callback fired when date or time is selected | |
| onShortcutClick | (shortcut: Range, event) => void | Callback fired when shortcut clicked | |
| onToggleMonthDropdown | (open: boolean) => void | Callback function that switches to the month view | |
| onToggleTimeDropdown | (open: boolean) => void | Callback function that switches to the time view | |
| open | boolean | Whether open the component | |
| placeholder | string | Placeholder | |
| placement | [Placement](#code-ts-placement-code) `('bottomStart')` | The placement of component | |
| preventOverflow | boolean | Prevent floating element overflow | |
| ranges | [Range[]](#code-ts-range-code) | Custom shortcut options | |
| renderCell | (date: Date) => ReactNode | Custom calendar cell rendering | ![][5.54.0] |
| renderValue | (date: Date, format: string) => string | Custom render value | |
| shouldDisableDate | (date:Date) => boolean | Disabled date | |
| shouldDisableHour | (hour:number, date:Date) => boolean | Disabled hours | |
| shouldDisableMinute | (minute:number, date:Date) => boolean | Disabled minutes | |
| shouldDisableSecond | (second:number, date:Date) => boolean | Disabled seconds | |
| showMeridiem | boolean | Display hours in 12 format | |
| showWeekNumbers | boolean | Whether to show week numbers | |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | A picker can have different sizes | |
| value | Date | The current value (controlled) | |
| weekStart | 0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6 `(0)` | The index of the first day of the week (0 - Sunday). If `isoWeek` is `true`, the value of `weekStart` is ignored | ![][5.62.0] |
#### `ts:Placement`
```ts
type Placement =
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd'
| 'auto'
| 'autoVerticalStart'
| 'autoVerticalEnd'
| 'autoHorizontalStart'
| 'autoHorizontalEnd';
```
#### `ts:Range`
```ts
interface Range {
label: ReactNode;
value: Date | ((date: Date) => Date);
closeOverlay?: boolean;
// Sets the position where the predefined range is displayed, the default is bottom.
placement?: 'bottom' | 'left';
}
```
#### `ts:MonthDropdownProps`
```ts
import type { FixedSizeListProps } from 'react-window';
interface MonthDropdownProps extends Partial {
/**
* The HTML element or React component to render as the root element of the MonthDropdown.
*/
as?: React.ElementType;
/**
* The HTML element or React component to render as each item in the MonthDropdown.
*/
itemAs?: React.ElementType;
/**
* The CSS class name to apply to each item in the MonthDropdown.
*/
itemClassName?: string;
}
```
[month-dropdown-props]: #code-ts-month-dropdown-props-code
[ISO-8601]: https://en.wikipedia.org/wiki/ISO_week_date
================================================================================
# Components: Date Range Input - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/date-range-input/en-US/index.md
================================================================================
# DateRangeInput
The DateRangeInput components let the user select a date range with the keyboard.
## Import
**Main import:**
```js
import { DateRangeInput } from 'rsuite';
```
**Individual import:**
```js
import DateRangeInput from 'rsuite/DateRangeInput';
// (Optional) Import component styles.
import 'rsuite/DateRangeInput/styles/index.css';
```
## Examples
### Basic
```js
import { DateRangeInput } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Customize the date format
```js
import { DateRangeInput, Stack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import { DateRangeInput, InputGroup, HStack, VStack, Text, Divider } from 'rsuite';
import CalendarIcon from '@rsuite/icons/Calendar';
const App = () => (
}>
Disabled
ReadOnly
Plaintext
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled vs. uncontrolled value
```js
import { DateRangeInput, VStack, HStack, Text, Divider, Button } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState([new Date('2023-10-01'), new Date('2023-10-31')]);
const handleChange = (value, event) => {
setValue(value);
console.log('Controlled Change', value);
};
return (
} >
Controlled Value
setValue(null)}>Clear
Uncontrolled Value
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- The DateRangeInput component is the `` element.
- When the DateRangeInput component is disabled, the `disabled` property is added to the `` element.
- When the DateRangeInput component is read only, the `readonly` property is added to the `` element.
### Keyboard interactions
- Use →← keyboard to navigate to the previous or next date segment.
- Use ↓↑ keys to increase and decrease values.
- Use Backspace key to delete selected value.
- Use numeric key to update selected value.
## Props
### ``
| Property | Type`(default)` | Description |
| ------------ | ------------------------------------------- | --------------------------------------------------------- |
| character | string `(' ~ ')` | The character between the start and end dates |
| defaultValue | [Date, Date]〡 null | The default value (uncontrolled) |
| disabled | boolean | Whether disabled the component |
| format | string `('dd/MM/yyyy')` | Format of the date when rendered in the input |
| onChange | (date: [Date, Date]〡 null , event) => void | Callback fired when value changed |
| plaintext | boolean | Whether plaintext the component |
| readOnly | boolean | Whether read only the component |
| size | 'lg'〡'md'〡'sm'〡'xs' `('md')` | Date input can have different sizes |
| value | [Date, Date]〡 null | The selected value. Used when the component is controlled |
================================================================================
# Components: Date Range Picker - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/date-range-picker/en-US/index.md
================================================================================
# DateRangePicker
DateRangePicker is used to quickly enter or pick a date and time range.
## Import
**Main import:**
```js
import { DateRangePicker } from 'rsuite';
```
**Individual import:**
```js
import DateRangePicker from 'rsuite/DateRangePicker';
// (Optional) Import component styles.
import 'rsuite/DateRangePicker/styles/index.css';
```
## Examples
### Basic
```js
import { DateRangePicker } from 'rsuite';
const App = () => {
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Customize the date format
```js
import { DateRangePicker, Stack } from 'rsuite';
import { FaCalendar, FaClock } from 'react-icons/fa';
import { BsCalendar2MonthFill } from 'react-icons/bs';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { DateRangePicker } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
```js
import { DateRangePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Block
```js
import { DateRangePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Placeholder
```js
import { DateRangePicker } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Select Whole Week, Whole Month
```js
import { DateRangePicker } from 'rsuite';
import { subDays } from 'date-fns/subDays';
import { addDays } from 'date-fns/addDays';
const App = () => (
Select Whole Week
Select Whole Week,
ISO 8601 standard
, each calendar week begins on Monday and Sunday is the seventh day
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Reference
- https://github.com/react-bootstrap/react-bootstrap
- https://github.com/facebook/fbjs
================================================================================
# Components: Drawer - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/drawer/en-US/index.md
================================================================================
# Drawer
A panel that slides out from the edge of the page can replace Modal to present more content.
## Import
**Main import:**
```js
import { Drawer } from 'rsuite';
```
**Individual import:**
```js
import Drawer from 'rsuite/Drawer';
// (Optional) Import component styles.
import 'rsuite/Drawer/styles/index.css';
```
- `Drawer` The container of Drawer.
- `Drawer.Body` The content of Drawer.
- `Drawer.Actions` The action buttons of Drawer, usually placed in the header of Drawer. (optional)
- `Drawer.Header` The header of Drawer, including the close button. (optional)
- `Drawer.Title` The title of Drawer, usually placed in the header of Drawer. (optional)
## Examples
### Basic
```js
import { Drawer, ButtonToolbar, Button, Placeholder } from 'rsuite';
const App = () => {
const [open, setOpen] = React.useState(false);
const [openWithHeader, setOpenWithHeader] = React.useState(false);
return (
<>
setOpen(true)}>Open setOpenWithHeader(true)}>Open with header setOpen(false)}>
setOpenWithHeader(false)}>
Drawer Title setOpenWithHeader(false)}>Cancel setOpenWithHeader(false)} appearance="primary">
Confirm
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Backdrop
Control the behavior of the Drawer's backdrop:
- `true`: Show backdrop, and clicking it will close the Drawer
- `false`: Do not show backdrop
- `'static'`: Show backdrop, but clicking it will not close the Drawer
```js
import { Drawer, SegmentedControl, ButtonToolbar, Button, Placeholder, Text } from 'rsuite';
const App = () => {
const [backdrop, setBackdrop] = React.useState('static');
const [open, setOpen] = React.useState(false);
return (
<>
setOpen(true)}>Open setOpen(false)}>
Drawer Title setOpen(false)}>Cancel setOpen(false)} appearance="primary">
Confirm
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Placement
The Drawer can slide out from four directions: `top`, `right`, `bottom`, `left`.
```js
import { Drawer, ButtonToolbar, Button, IconButton, Placeholder } from 'rsuite';
import { RxArrowUp, RxArrowDown, RxArrowLeft, RxArrowRight } from 'react-icons/rx';
const App = () => {
const [open, setOpen] = React.useState(false);
const [placement, setPlacement] = React.useState();
const handleOpen = key => {
setOpen(true);
setPlacement(key);
};
return (
setOpen(false)}>
Drawer Title setOpen(false)}>Cancel setOpen(false)} appearance="primary">
Confirm
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Size
Set the width (or height, depending on the `placement` prop) of the Drawer using the `size` prop.
```js
import { Drawer, SegmentedControl, ButtonToolbar, Button, IconButton, Placeholder } from 'rsuite';
const App = () => {
const [size, setSize] = React.useState();
const [open, setOpen] = React.useState(false);
const [placement, setPlacement] = React.useState('right');
const handleOpen = value => {
setSize(value);
setOpen(true);
};
return (
<>
handleOpen('xs')}>
Xsmall
handleOpen('sm')}>
Small
handleOpen('md')}>
Medium
handleOpen('lg')}>
Large
handleOpen('full')}>
Full page
handleOpen(400)}>
size=400 handleOpen('50rem')}>
size='50rem' handleOpen('calc(100% - 120px)')}>
size='calc(100% - 120px)' setOpen(false)}>
Drawer Title setOpen(false)}>Cancel setOpen(false)} appearance="primary">
Confirm
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### With Form
Place a form inside the Drawer, suitable for scenarios requiring user input.
```js
import {
Form,
Button,
Input,
Drawer,
Textarea,
SelectPicker,
PasswordInput,
PasswordStrengthMeter
} from 'rsuite';
const selectData = ['Developer', 'Designer', 'Manager', 'Analyst', 'Tester'].map(item => ({
label: item,
value: item
}));
const requirements = [
{ re: /[0-9]/ },
{ re: /[a-z]/ },
{ re: /[A-Z]/ },
{ re: /[+,:;=?@#|'<>.^*()%!-_]/ }
];
function getStrengthLevel(password) {
const passed = requirements.reduce((acc, req) => acc + req.re.test(password), 0);
const hasLength = password.length >= 8;
// 0: very weak, 1: weak, 2: fair, 3: strong
if (passed <= 1) return 0;
if (passed === 2) return 1;
if (passed === 3) return 2;
if (passed === requirements.length && hasLength) return 3;
return 2;
}
const strengthLabels = ['Very weak', 'Weak', 'Fair', 'Strong'];
const App = () => {
const [open, setOpen] = React.useState(false);
const [formValue, setFormValue] = React.useState({
fullName: '',
email: '',
password: '',
bio: '',
role: ''
});
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
const level = getStrengthLevel(formValue.password);
return (
<>
Create New Employee Account
Submit
Cancel
Full Name
Enter your full name as it appears on official documents
Work EmailUse your company email addressCreate PasswordBrief BioA short description of your professional backgroundJob RoleSelect the role that best describes your positionAdd New Employee
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
On mobile devices, the maximum width of the Drawer will fill the entire screen.
## Accessibility
### ARIA Attributes
- The `role` attribute of the Drawer component is set to `dialog`.
- Use the `aria-labelledby` attribute to associate with Drawer.Title.
- Use the `aria-describedby` attribute to provide a description for Drawer.Body.
### Keyboard Interaction
- ESC can close the Drawer. This functionality can be disabled by setting `keyboard=false`.
- Tab When the Drawer is open, focus automatically moves inside the Drawer. Pressing Tab cycles through focusable elements within the Drawer.
- Shift + Tab Reverse cycles through focusable elements within the Drawer.
- When the Drawer closes, focus returns to the element that triggered the Drawer to open.
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| autoFocus | boolean `(true)` | When set to true, the Drawer is opened and is automatically focused on its own, accessible to screen readers |
| backdrop | boolean \| 'static' | When set to true, the Drawer will display the background when it is opened. Clicking on the background will close the Drawer. If you do not want to close the Drawer, set it to 'static'. |
| backdropClassName | string | Add an optional extra class name to .modal-backdrop It could end up looking like class="modal-backdrop foo-modal-backdrop in". |
| classPrefix | string `('drawer')` | The prefix of the component CSS class |
| closeButton | ReactNode \| boolean | Custom close button, set to false to hide close button |
| container | HTMLElement \| (() => HTMLElement) | Sets the rendering container |
| enforceFocus | boolean `(true)` | When set to true, Drawer will prevent the focus from leaving when opened, making it easier for the secondary screen reader to access |
| keyboard | boolean | close Drawer when press `esc` |
| onClose | () => void | Callback fired when Drawer hide |
| onEnter | () => void | Callback fired before the Drawer transitions in |
| onEntered | () => void | Callback fired after the Drawer finishes transitioning in |
| onEntering | () => void | Callback fired as the Drawer begins to transition in |
| onExit | () => void | Callback fired right before the Drawer transitions out |
| onExited | () => void | Callback fired after the Drawer finishes transitioning out |
| onExiting | () => void | Callback fired as the Drawer begins to transition out |
| onOpen | () => void | Callback fired when Drawer display |
| open \* | boolean | Open Drawer |
| placement | [Placement](#code-ts-placement-code)`(right)` | The placement of Drawer |
| size | 'xs' \| 'sm' \| 'md' \| lg' \| 'full' \| number \| string | Set Drawer size |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------- | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('modal-header')` | The prefix of the component CSS class |
| closeButton | boolean `(true)` | When set to true, a close button will be displayed |
| onClose | (event) => void | Callback function when clicking the close button |
| children | ReactNode | The content of the Header |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------ | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('modal-title')` | The prefix of the component CSS class |
| children | ReactNode | The content of the Title |
### ``
| Property | Type `(Default)` | Description |
| ----------- | -------------------------- | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('modal-actions')` | The prefix of the component CSS class |
| children | ReactNode | The content of the Actions |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ----------------------- | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('modal-body')` | The prefix of the component CSS class |
| children | ReactNode | The content of the Body |
#### `ts:Placement`
```ts
type Placement = 'top' | 'bottom' | 'right' | 'left';
```
================================================================================
# Components: Dropdown - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/dropdown/en-US/index.md
================================================================================
# Dropdown
Used to create an easily accessible dropdown menu, providing multiple options for users to choose from
## Import
**Main import:**
```js
import { Dropdown } from 'rsuite';
```
**Individual import:**
```js
import Dropdown from 'rsuite/Dropdown';
// (Optional) Import component styles.
import 'rsuite/Dropdown/styles/index.css';
```
- `Dropdown` Drop-down menu.
- `Dropdown.Item` Drop-down menu options.
- `Dropdown.Menu` A submenu is created in the Drop-down menu.
- `Dropdown.Separator` A Separator in the Drop-down menu.
## Examples
### Basic
```js
import { Dropdown } from 'rsuite';
const App = () => (
New FileNew File with Current ProfileDownload As...Export PDFExport HTMLSettingsAbout
);
ReactDOM.render(, document.getElementById('root'));
```
### Trigger
Set the trigger event with the `trigger` attribute, support the event:
- `click` (default)
- `hover`
- `contextMenu`
```js
import { Dropdown } from 'rsuite';
const CustomDropdown = ({ ...props }) => (
New FileNew File with Current ProfileDownload As...Export PDFExport HTMLSettingsAbout
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled
You can disable the entire component or disable individual options by configuring the `disabled` property.
```js
import { Dropdown, ButtonToolbar } from 'rsuite';
const App = () => (
Item 1Item 2Item 3Item 1Item 2Item 3 - Disabled
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { Dropdown, ButtonToolbar } from 'rsuite';
const SizeDropdown = props => (
New FileNew File with Current ProfileDownload As...Export PDFExport HTMLSettingsAbout
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### No caret variation
```js
import { Dropdown } from 'rsuite';
const App = () => (
New FileNew File with Current ProfileDownload As...Export PDFExport HTMLSettingsAbout
);
ReactDOM.render(, document.getElementById('root'));
```
### With Shortcut
```js
import { Dropdown } from 'rsuite';
const App = () => (
CopyCutPastePaste to replaceFind...Find and replace...Find nextFind previousSelect allSoft undoDuplicate selectionSelect lineFind all selections
);
ReactDOM.render(, document.getElementById('root'));
```
### With Icons
```js
import { Dropdown } from 'rsuite';
import PageIcon from '@rsuite/icons/Page';
import IdInfoIcon from '@rsuite/icons/IdInfo';
import DetailIcon from '@rsuite/icons/Detail';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
const App = () => (
}>
} shortcut="⌘ N">
New File
} shortcut="⌘ ⇧ N">
New File with Current Profile
} shortcut="⌘ ⇧ S">
Download As...
} shortcut="⌘ P">
Export PDF
);
ReactDOM.render(, document.getElementById('root'));
```
### With Description
```js
import { Dropdown, Box } from 'rsuite';
import PageIcon from '@rsuite/icons/Page';
import IdInfoIcon from '@rsuite/icons/IdInfo';
import DetailIcon from '@rsuite/icons/Detail';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
const DropdownIcon = ({ as: Component }) => (
);
const App = () => (
}>
}
shortcut="⌘ N"
description="Create a new file"
>
New File
}
shortcut="⌘ ⇧ N"
description="Create a new file with current profile"
>
New File with Current Profile
}
shortcut="⌘ ⇧ S"
description="Download the selected file as a word document"
>
Download As...
}
shortcut="⌘ P"
description="Export the selected file as a PDF"
>
Export PDF
);
ReactDOM.render(, document.getElementById('root'));
```
### Separator and Panel
- Use `` to set the separator.
- Use the `panel` prop to set a `Dropdown.Item` as a panel.
```js
import { Dropdown, Avatar } from 'rsuite';
const renderToggle = props => (
);
const App = () => (
Signed in as
TonyYour profileYour starsYour GistsHelpSettingsSign out
);
ReactDOM.render(, document.getElementById('root'));
```
### Placement
```js
import { Dropdown } from 'rsuite';
import { PlacementCornerGrid } from '@/components/PlacementGrid';
const items = [
New File,
New File with Current Profile,
Download As...,
Export PDF,
Export HTML,
Settings,
About
];
const App = () => (
(
{items}
)}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Submenu
```js
import { Dropdown } from 'rsuite';
const minWidth = 120;
const App = () => (
Item 1Item 2-1-1Item 2-1-2Item 2-1-3Item 2-2Item 2-3Item 3-1-1Item 3-1-2Item 3-1-3Item 3-2Item 3-3
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Toggle
```js
import { Dropdown, IconButton } from 'rsuite';
import PlusIcon from '@rsuite/icons/Plus';
import PageIcon from '@rsuite/icons/Page';
import IdInfoIcon from '@rsuite/icons/IdInfo';
import DetailIcon from '@rsuite/icons/Detail';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
const renderIconButton = (props, ref) => {
return (
} circle color="blue" appearance="primary" />
);
};
const renderButton = (props, ref) => {
return (
New File
);
};
const App = () => (
<>
}>New File
}>New File with Current Profile
}>Download As...
}>Export PDF
}>New File
}>New File with Current Profile
}>Download As...
}>Export PDF
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Used with Buttons
```js
import { Dropdown, ButtonToolbar, Popover, IconButton } from 'rsuite';
import ArrowDownIcon from '@rsuite/icons/ArrowDown';
import PlusIcon from '@rsuite/icons/Plus';
const renderMenu = ({ onClose, left, top, className }, ref) => {
const handleSelect = eventKey => {
onClose();
console.log(eventKey);
};
return (
);
};
const App = () => (
} circle />
} placement="left">
New
Create} />
);
ReactDOM.render(, document.getElementById('root'));
```
### Routing Library
The `` component works with frameworks and client side routers like Next.js and React Router. See the [Composition Guide](https://rsuitejs.com/guide/composition/#third-party-routing-library) for setup instructions.
```js
import { Dropdown } from 'rsuite';
import Link from 'next/link';
const App = () => (
Guide
Components
Resources
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(default)` | Description |
| ---------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------- |
| activeKey | string | The option to activate the state, corresponding to the `eventkey` in the Dropdown.item. |
| classPrefix | string `('dropdown')` | The prefix of the component CSS class |
| defaultOpen | boolean `(false)` | Whether Dropdown is initially open |
| disabled | boolean | Whether or not component is disabled |
| icon | Element<typeof Icon> | Set the icon |
| menuStyle | CSSProperties | The style of the menu. |
| noCaret | boolean | Do not display the arrow icon |
| onClose | () => void | The callback function that the menu closes |
| onOpen | () => void | Menu Pop-up callback function |
| onSelect | (eventKey: string, event) => void | Selected callback function |
| onToggle | (open?: boolean, event?: React.SyntheticEvent) => void | Callback function for menu state switching |
| open | boolean | Controlled open state |
| placement | [Placement](#code-ts-placement-code) | The placement of Menu |
| renderMenuButton | (props: ButtonProps, ref: Ref) => ReactElement | Custom render menu button |
| renderMenuPopup | (props: MenuProps, ref: Ref) => ReactElement | Custom render menu popup |
| title | ReactNode | Menu title |
| trigger | [Trigger](#code-ts-trigger-code) `('click')` | Triggering events |
### ``
| Property | Type`(default)` | Description | Version |
| ----------- | --------------------------------- | ---------------------------------------------------- | ----------- |
| active | boolean | Active the current option | |
| as | ElementType`('li')` | You can use a custom element type for this component | |
| children \* | ReactNode | The content of the component | |
| classPrefix | string `('dropdown-item')` | The prefix of the component CSS class | |
| disabled | boolean | Disable the current option | |
| divider | boolean | Whether to display the divider | |
| eventKey | string | The value of the current option | |
| icon | Element<typeof Icon> | Set the icon | |
| onSelect | (eventKey: string, event) => void | Select the callback function for the current option | |
| panel | boolean | Displays a custom panel | |
| shortcut | string | The dropdown item keyboard shortcut | ![][5.58.0] |
### ``
| Property | Type`(default)` | Description |
| -------- | -------------------------- | ----------------------------- |
| icon | Element<typeof Icon> | Set the icon |
| title | string | Define the title as a submenu |
### ``
| Property | Type`(default)` | Description |
| -------- | -------------------- | ---------------------------------------------------- |
| as | ElementType `('li')` | You can use a custom element type for this component |
#### `ts:Placement`
```ts
type Placement =
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd';
```
#### `ts:Trigger`
```ts
type Trigger = 'click' | 'hover' | 'contextMenu' | Array<'click' | 'hover' | 'contextMenu'>;
```
================================================================================
# Components: Form - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/form/en-US/index.md
================================================================================
# Form
A set of components and models that process form data.
## Import
- **Basic**:
- `Form`: Used to define forms that support data validation.
- `Form.Label`: Title corresponding to the form field.
- `Form.Control`: Defines the control for the form field. Defaults to the `Input` component. Can customize the component through the `accepter` property.
- **Layout**:
- `Form.Stack`: Used to layout a group of form controls.
- `Form.Group`: Used to layout a single form control.
- **Field State**:
- `Form.Text`: Provides help information for form fields.
- `Form.ErrorMessage`: Displays error message for form fields.
- **Hooks**
- `useFormControl`: A hook that provides form control functionality for custom form components, enabling seamless integration with the Form component.
## Layouts
---
### Vertical Layout
```js
import { Form, ButtonToolbar, Button, Input, HStack, PasswordInput, Textarea } from 'rsuite';
const FormField = ({ name, label, text, ...props }) => (
{label}
{text && {text}}
);
const App = () => {
return (
SubmitCancel
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Fluid
The `fluid` property allows the Input 100% of the form to fill the container, valid only in vertical layouts.
```js
import { Form, ButtonToolbar, Button, Input, InputGroup, NumberInput, Textarea } from 'rsuite';
const FormField = ({ name, label, text, ...props }) => (
{label}
{text && {text}}
);
const InputGroupField = React.forwardRef((props, ref) => (
));
const App = () => (
SubmitCancel
);
ReactDOM.render(, document.getElementById('root'));
```
### Horizontal Layout
```js
import { Form, Input, ButtonToolbar, Button, HStack, VStack, Textarea } from 'rsuite';
const App = () => (
UsernameRequiredEmailRequiredPasswordTextareaSubmitCancel
);
ReactDOM.render(, document.getElementById('root'));
```
### Inline Layout
```js
import EyeCloseIcon from '@rsuite/icons/EyeClose';
import VisibleIcon from '@rsuite/icons/Visible';
import { Form, Button, HStack, InputGroup, Input, PasswordInput } from 'rsuite';
const App = () => (
<>
UsernameRequiredPasswordLogin
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Layout In Modal
```js
import { Form, Button, Input, Modal, SelectPicker, PasswordInput, Textarea } from 'rsuite';
const selectData = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice'].map(item => ({
label: item,
value: item
}));
const FormField = ({ name, label, text, ...props }) => (
{label}
{text && {text}}
);
const App = () => {
const [open, setOpen] = React.useState(false);
const [formValue, setFormValue] = React.useState({
name: '',
email: '',
password: '',
textarea: ''
});
const handleClose = () => {
setOpen(false);
};
const handleOpen = () => {
setOpen(true);
};
return (
<>
New User
Confirm
Cancel
New User
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Status
---
### Help Text
`` A help description can be defined below the form component. If the `tooltip` property is set, an icon will be displayed on the form component and the help description information will be displayed as ``.
```js
import { Form, HStack } from 'rsuite';
const App = () => (
This field is requiredThis field is required
);
ReactDOM.render(, document.getElementById('root'));
```
### Error Message
Error message can be set in 2 ways:
- The `` component passes an `errorMessage` property setting error message, and `errorPlacement` sets the location of the error message display.
- Customize a prompt message.
```js
import {
Form,
InputGroup,
Input,
Toggle,
SelectPicker,
HStack,
VStack,
Box,
Divider
} from 'rsuite';
import AvatarIcon from '@rsuite/icons/legacy/Avatar';
const errorPlacementData = [
{ label: 'Static', value: 'static' },
{ label: 'Bottom Start', value: 'bottomStart' },
{ label: 'Bottom End', value: 'bottomEnd' },
{ label: 'Top Start', value: 'topStart' },
{ label: 'Top End', value: 'topEnd' },
{ label: 'Left Start', value: 'leftStart' },
{ label: 'Right Start', value: 'rightStart' },
{ label: 'Left End', value: 'leftEnd' },
{ label: 'Right End', value: 'rightEnd' }
];
const App = () => {
const [errorVisible, setErrorVisible] = React.useState(true);
const [errorPlacement, setErrorPlacement] = React.useState('static');
const errorMessage = errorVisible ? 'This field is required' : null;
return (
} h={368} spacing={40} align="flex-start">
InputInputGroupCustom error messages{errorMessage}
{errorMessage}
);
};
const InputGroupField = React.forwardRef((props, ref) => (
));
const CustomErrorMessage = ({ show, children }) => {
return (
{children}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
```js
import {
Form,
Button,
ButtonToolbar,
RadioGroup,
Radio,
Checkbox,
CheckboxGroup,
SegmentedControl,
Slider,
DatePicker,
DateRangePicker,
CheckPicker,
SelectPicker,
TagPicker,
InputPicker,
Cascader,
MultiCascader,
Rate,
Panel,
Toggle,
HStack
} from 'rsuite';
import { mockTreeData } from './mock';
const tree = mockTreeData({ limits: [2, 3, 3], labels: ['Provincial', 'County', 'Town'] });
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice'].map(item => ({
label: item,
value: item
}));
const defaultFormValue = {
input: '',
checkbox: [],
radio: '',
slider: 0,
datePicker: null,
dateRangePicker: null,
checkPicker: [],
selectPicker: '',
tagPicker: [],
inputPicker: '',
cascader: '',
multiCascader: [],
rate: 0,
enable: false
};
const initFormValue = {
input: 'A suite of React components, sensible UI design, and a friendly development experience.',
checkbox: ['Node.js', 'CSS3', 'HTML5'],
radio: 'HTML5',
slider: 10,
datePicker: new Date(),
dateRangePicker: [new Date(), new Date()],
checkPicker: ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice'],
selectPicker: 'Eugenia',
tagPicker: ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice'],
inputPicker: 'Eugenia',
cascader: '1-1-2',
multiCascader: ['1-1-2', '1-1-3'],
rate: 2
};
const FormField = ({ name, label, text, ...props }) => (
{label}
{text && {text}}
);
const App = () => {
const [formValue, setFormValue] = React.useState(initFormValue);
const [status, setStatus] = React.useState('disabled');
const disabled = status === 'disabled';
const readOnly = status === 'readonly';
const plaintext = status === 'plaintext';
return (
setFormValue(defaultFormValue)}>Clear form data setFormValue(initFormValue)}>ResetNode.jsWebpackCSS3JavascriptHTML5Node.jsWebpackCSS3JavascriptHTML5
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- You should set the `aria-label` or `aria-labelledby` property for each form so that the screen reader can read the purpose of the form correctly.
- Through the `controlId` prop of ``, you can set `id` on `` and set `htmlFor` on ``. In addition, `aria-labelledby` and `aria-describeby` will be generated for ``, corresponding to the `id` of `` and ``.
```jsx
UsernameUsername is required
```
HTML:
```html
Username is required
```
### Required JavaScript features
- Click the button of `type='submit'` in the Form, and the submit event of the form will be triggered automatically.
## Props
### ``
![][6.0.0]
| Property | Type`(default)` | Description |
| ----------- | ----------------------------------------------------- | --------------------------------------------------------------- |
| classPrefix | string `('form-stack')` | CSS class prefix for the component |
| fluid | boolean | Enables the Input to occupy 100% width in vertical layouts only |
| layout | 'horizontal' \| 'vertical' \| 'inline' `('vertical')` | The layout style of the form |
| spacing | number | Spacing between form controls |
### ``
| Property | Type`(default)` | Description |
| ---------------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| accepter | ElementType `(Input)` | Component to be used as the input. |
| checkAsync | boolean | Enables asynchronous validation. |
| checkTrigger | 'change' \| 'blur' \| 'none' | Overrides the form's validation trigger type for this control. |
| classPrefix | string `('form-control')` | CSS class prefix for the component. |
| errorMessage | ReactNode | Displays error messages. |
| errorPlacement | [Placement](#code-ts-placement-code)`('bottomStart')` | Specifies where to display error messages. |
| name \* | string | Name attribute for the control, supports nested paths like `address.city` for form value management. |
| plaintext | boolean | Renders the control in plain text. |
| readOnly | boolean | Sets the control to read-only mode. |
| rule | checkType | Validation rule for the field. Overrides form-level `model` validation if there's a conflict, [example](/components/form-validation/#field-level-verification-rules). |
| shouldResetWithUnmount | boolean`('false')` | Removes the field value and error message when the component is unmounted. |
### ``
| Property | Type`(default)` | Description |
| ----------- | ----------------------- | ------------------------------------------------------------------------------- |
| classPrefix | string `('form-group')` | CSS class prefix for the component |
| controlId | string | Assigns an id to the `` and sets `htmlFor` on the ``. |
### ``
| Property | Type`(default)` | Description |
| ----------- | ------------------------------- | --------------------------------------------------------------------------------- |
| classPrefix | string `('form-control-label')` | CSS class prefix for the component |
| htmlFor | string | The `for` attribute of the HTML label tag, defaults to the Form.Group's controlId |
### ``
| Property | Type`(default)` | Description |
| ----------- | --------------------------- | --------------------------------------------------------------------------------- |
| classPrefix | string `('form-help-text')` | CSS class prefix for the component |
| htmlFor | string | The `for` attribute of the HTML label tag, defaults to the Form.Group's controlId |
| tooltip | boolean | Shows the text through a Tooltip component |
### ``
| Property | Type`(default)` | Description |
| ----------- | ----------------------------------------------------- | ------------------------------------------- |
| classPrefix | string `('form-error-message')` | CSS class prefix for the component |
| placement | [Placement](#code-ts-placement-code)`('bottomStart')` | Specifies where to display error messages |
| show | boolean | Toggles the visibility of the error message |
### Form Ref
| Name | Type | Description |
| ------------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------- |
| check | (callback?: (formError: E) => void) => boolean | Verify form data |
| checkAsync | () => Promise | Asynchronously check form data |
| checkForField | (fieldName: string, callback?: (checkResult: CheckResult) => void) => boolean | Checklist single field value |
| checkForFieldAsync | (fieldName: string) => Promise | Asynchronous check form single field value |
| cleanErrorForField | (fieldName: string, callback?: () => void) => void | Clear single field error message |
| cleanErrors | (callback: () => void) => void | Clean error message |
| reset | () => void | Reset form data to initial value and clear all error messages |
| resetErrors | () => void | Reset error message |
| submit | () => void | Trigger form submission and verify data |
### Schema
Schema depends on the [schema-typed](https://github.com/rsuite/schema-typed#schema-typed) library for defining data models.
#### `ts:Placement`
```ts
/**
* Placement options for error messages in form controls.
* The `static` option is supported from v6.0.0 onwards.
*/
type ErrorMessagePlacement =
| 'static'
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd';
```
## Hooks
### `useFormControl`
![][6.0.0]
The `useFormControl` hook provides form control functionality for custom form components. It must be used within a `;
```
================================================================================
# Components: Form Formik - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/form-formik/en-US/index.md
================================================================================
# Formik integration 🧩
React Suite can be coupled smoothly with [Formik](https://formik.org/). This guide will show you how to use Formik with React Suite.
## Usage
The following will use the `useFormik` hook to create a simple form with the `Input` component.
```jsx
import { useFormik } from 'formik';
import { Input, Button } from 'rsuite';
const App = () => {
const formik = useFormik({
initialValues: {
name: ''
},
onSubmit: values => {
console.log(values);
}
});
return (
);
};
```
## Examples
### Basic
```js
import { useFormik } from 'formik';
import { Input, Button, Stack } from 'rsuite';
const App = () => {
const formik = useFormik({
initialValues: {
name: '',
email: ''
},
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
}
});
return (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Validation
```js
import { useFormik } from 'formik';
import { Input, Button, Form } from 'rsuite';
const Field = ({ error, ...rest }) => {
return (
{error}
);
};
const App = () => {
const formik = useFormik({
initialValues: {
name: '',
email: ''
},
validate: values => {
const errors = {};
if (!values.name) {
errors.name = 'Required';
}
if (!values.email) {
errors.email = 'Required';
} else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
errors.email = 'Invalid email address';
}
return errors;
},
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
}
});
return (
formik.setFieldValue('name', value)}
/>
formik.setFieldValue('email', value)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Validation with Yup
Yup is a schema builder for runtime value parsing and validation. Formik integrates well with Yup, making it easy to use Yup schemas with Formik forms.
```js
import { useFormik } from 'formik';
import { Input, Button, Form } from 'rsuite';
import * as Yup from 'yup';
const Field = ({ error, ...rest }) => {
return (
{error}
);
};
const validationSchema = Yup.object().shape({
name: Yup.string().required('Required'),
email: Yup.string().email('Invalid email address').required('Required')
});
const App = () => {
const formik = useFormik({
initialValues: {
name: '',
email: ''
},
validationSchema,
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
}
});
return (
formik.setFieldValue('name', value)}
/>
formik.setFieldValue('email', value)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
> If you prefer to use Zod, consider using the community-provided adapter [zod-formik-adapter](https://www.npmjs.com/package/zod-formik-adapter).
### Other data entry components
All data entry components in React Suite can be used with Formik. The following will demonstrate how to use Formik with the `DatePicker` and `Rate` components.
```js
import { useFormik } from 'formik';
import { Input, Button, Form, DatePicker, Rate } from 'rsuite';
import * as Yup from 'yup';
const Field = ({ error, as: Component = Input, ...rest }) => {
return (
{error}
);
};
const validationSchema = Yup.object().shape({
date: Yup.date().required('Date is required'),
rating: Yup.number()
.required('Rating is required')
.min(2, 'Rating must be at least 2')
.max(5, 'Rating must be at most 5')
});
const App = () => {
const formik = useFormik({
initialValues: {
date: new Date(),
rating: 3
},
validationSchema,
onSubmit: values => {
alert(JSON.stringify(values, null, 2));
}
});
return (
formik.setFieldValue('date', value)}
/>
formik.setFieldValue('rating', value)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
================================================================================
# Components: Form React Hook Form - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/form-react-hook-form/en-US/index.md
================================================================================
# React Hook Form integration 🧩
React Suite's form components can be used with [React Hook Form](https://react-hook-form.com/). React Hook Form is a simple, flexible and powerful form validation library that helps you easily manage form state and validation.
## Usage
```jsx
import { useForm, Controller } from 'react-hook-form';
import { Input, Button, Form } from 'rsuite';
const App = () => {
const defaultValues = { name: '' };
const { control, handleSubmit } = useForm({ defaultValues });
const onSubmit = data => alert(JSON.stringify(data, null, 2));
return (
);
};
```
## Examples
### Basic
```js
import { useForm, Controller } from 'react-hook-form';
import { Input, Button, Form } from 'rsuite';
const App = () => {
const defaultValues = {
name: '',
email: ''
};
const { control, handleSubmit } = useForm({ defaultValues });
const onSubmit = data => alert(JSON.stringify(data, null, 2));
return (
(
field.onChange(value)}
placeholder="Name"
/>
)}
/>
(
field.onChange(value)}
placeholder="Email"
/>
)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Validation
```js
import { useForm, Controller } from 'react-hook-form';
import { Input, Button, Form } from 'rsuite';
const Field = ({ as: Component = Input, field, error, ...rest }) => {
return (
field.onChange(value)}
{...rest}
/>
{error}
);
};
const App = () => {
const defaultValues = {
name: '',
email: ''
};
const {
control,
handleSubmit,
formState: { errors }
} = useForm({ defaultValues });
const onSubmit = data => alert(JSON.stringify(data, null, 2));
return (
(
)}
/>
(
)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Validation with Yup
react-hook-form provides a [validation resolver](https://github.com/react-hook-form/resolvers) that can be integrated with popular validation libraries, including: Yup, Zod, AJV, Joi, Superstruct, Vest, class-validator, io-ts, typanion, Ajv, TypeBox, Valibot and nope.
The following is an example using Yup validation:
```js
import { useForm, Controller } from 'react-hook-form';
import { Input, Button, Form } from 'rsuite';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
const Field = ({ as: Component = Input, field, error, ...rest }) => {
return (
field.onChange(value)}
{...rest}
/>
{error}
);
};
const validationSchema = Yup.object().shape({
name: Yup.string().required('Required'),
email: Yup.string().email('Invalid email address').required('Required')
});
const App = () => {
const defaultValues = {
name: '',
email: ''
};
const {
control,
handleSubmit,
formState: { errors }
} = useForm({ defaultValues, resolver: yupResolver(validationSchema) });
const onSubmit = data => alert(JSON.stringify(data, null, 2));
return (
(
)}
/>
(
)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Other data entry components
All data entry components in React Suite can be used with React Hook Form. The following example demonstrates how to use React Hook Form with the `DatePicker` and `Rate` components.
```js
import { useForm, Controller } from 'react-hook-form';
import { DatePicker, Rate, Button, Form } from 'rsuite';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
const Field = ({ as: Component, field, error, ...rest }) => {
return (
field.onChange(value)}
{...rest}
/>
{error}
);
};
const validationSchema = Yup.object().shape({
date: Yup.date().required('Date is required'),
rating: Yup.number()
.required('Rating is required')
.min(2, 'Rating must be at least 2')
.max(5, 'Rating must be at most 5')
});
const App = () => {
const defaultValues = {
date: new Date(),
rating: 2
};
const {
control,
handleSubmit,
formState: { errors }
} = useForm({ defaultValues, resolver: yupResolver(validationSchema) });
const onSubmit = data => alert(JSON.stringify(data, null, 2));
return (
(
)}
/>
(
)}
/>
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
================================================================================
# Components: Form Validation - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/form-validation/en-US/index.md
================================================================================
# Form validation
We recommend using [`schema-typed`](https://github.com/rsuite/schema-typed) to manage and validate form data. `rsuite` integrates `schema-typed` by default, and you can define the data model of the form through the `Schema` object. It can help us define data models, validate data, and generate error messages.
## Usage
Import Form and Schema
```jsx
import { Form } from 'rsuite';
import { SchemaModel, StringType } from 'rsuite/Schema';
```
Use SchemaModel to define the data model
```jsx
const model = SchemaModel({
name: StringType().isRequired('This field is required.'),
email: StringType().isEmail('Please enter a valid email address.')
});
```
## Examples
### Default check
The form will automatically trigger the data check after the `submit` event is triggered.
```js
import { Form, Button, ButtonToolbar } from 'rsuite';
import { SchemaModel, StringType } from 'rsuite/Schema';
const model = SchemaModel({
name: StringType().isRequired('This field is required.'),
email: StringType()
.isEmail('Please enter a valid email address.')
.isRequired('This field is required.')
});
function TextField(props) {
const { name, label, accepter, ...rest } = props;
return (
{label}
);
}
function App() {
return (
Submit
);
}
ReactDOM.render(, document.getElementById('root'));
```
### Schema Model
Form Check needs to be used `` and `Schema` 。
- `` Define a Field that corresponds to the `key` of the `SchemaModel` object via the `name` property. For detailed reference: Custom Form Components.
- `SchemaModel` Define a data model, using the reference [schema](https://github.com/rsuite/schema-typed#schema-typed).
- Custom trigger check: `{label}
);
});
const App = () => {
const formRef = React.useRef();
const [formError, setFormError] = React.useState({});
const [formValue, setFormValue] = React.useState({
name: '',
email: '',
age: '',
password: '',
confirmPassword: ''
});
const handleSubmit = () => {
if (!formRef.current.check()) {
console.error('Form Error');
return;
}
console.log(formValue, 'Form Value');
};
const handleCheckEmail = () => {
formRef.current.checkForField('email', checkResult => {
console.log(checkResult);
});
};
return (
Submit
Check Email
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Field level Verification rules
When there are more and more Fields, huge `model` codes or files are generated. And since in the definition at the top level, it is not flexible enough(ex: If a new Field is added or a Field is deleted, Normally you also need to manipulate the `model` at the top level)
At this time, the verification rules of the Field level may be a better choice. It adds it when the component is mounted, and delete it when the component is unmounted.
- `` supports adding verification rule for the current Field via the `rule` attribute.
```js
import { Form, Button } from 'rsuite';
import { StringType } from 'rsuite/Schema';
const nameRule = StringType().isRequired('This field is required.');
const emailRule = StringType().isEmail('Please enter a valid email address.');
function UsernameField() {
return (
Username
);
}
function EmailField() {
return (
Email
);
}
function App() {
return (
Submit
);
}
ReactDOM.render(, document.getElementById('root'));
```
### Asynchronous check
Under certain conditions, we need to perform asynchronous verification on the data, such as verifying whether the username is duplicated. The following example will illustrate the processing of asynchronous verification.
- Set the `checkAsync` property on `` that requires asynchronous validation.
- The validation rules for asynchronous validation add an object with a return value of Promise via the `addRule` method of `schema`.
- The check can be triggered manually by calling `checkAsync` and `checkForFieldAsync` of `
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Form Control
All Data Entry-related components can be used in forms such as `Checkbox`, `SelectPicker`, `Slider`, and so on. But you need to use the `Form.Control` component for data management and data association with the `Form` component.
- `Form.Control` used to bind data fields in a Form, passing the `name` attribute to the `key` of the SchemaModel object.
- `Form.Control` the default is an `Input` component, which can be set through the ʻaccepter` component.
```js
import {
Form,
Button,
CheckboxGroup,
RadioGroup,
Checkbox,
Radio,
CheckPicker,
NumberInput,
Slider,
DatePicker,
Message,
toaster,
Row,
Col,
Toggle
} from 'rsuite';
import { SchemaModel, StringType, ArrayType } from 'rsuite/Schema';
const Field = React.forwardRef((props, ref) => {
const { name, message, label, accepter, error, ...rest } = props;
return (
{label} {message}
);
});
const model = SchemaModel({
skills: ArrayType()
.minLength(2, 'Please select at least 2 types of Skills.')
.isRequired('This field is required.'),
status: ArrayType()
.minLength(2, 'Please select at least 2 types of Status.')
.isRequired('This field is required.'),
level: NumberType().min(5, 'This field must be greater than 5')
});
const App = () => {
const formRef = React.useRef();
const [formError, setFormError] = React.useState({});
const [formValue, setFormValue] = React.useState({
number: 10,
skills: ['Node.js'],
browser: 'Chrome',
status: ['open'],
level: 1,
level2: 1,
createDate: new Date(),
toggle: true
});
const handleSubmit = () => {
if (!formRef.current.check()) {
toaster.push(Error);
return;
}
toaster.push(Success);
};
return (
Node.jsCSS3JavascriptHTML5ChromeFireFoxIE
Submit
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Third-Party Libraries
Sometimes you need to customize form components or be compatible with third-party components. For example [react-select](https://github.com/JedWatson/react-select).
```js
import { Form, Button, Message, toaster, Row, Col } from 'rsuite';
import { SchemaModel, StringType } from 'rsuite/Schema';
import Select from 'react-select';
const Field = React.forwardRef((props, ref) => {
const { name, message, label, accepter, error, ...rest } = props;
return (
{label} {message}
);
});
const model = SchemaModel({
foods: StringType().isRequired('This field is required.')
});
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
];
const CustomSelect = React.forwardRef((props, ref) => {
const { value, onChange, ...rest } = props;
return (
}>
Required}>
);
ReactDOM.render(, document.getElementById('root'));
```
### Masked Input
MaskedInput is an input mask component. It can create input masks for phone numbers, dates, currencies, zip codes, percentages, emails, and almost anything.
```js
import { SelectPicker, Toggle, MaskedInput, HStack, VStack, Divider, Box } from 'rsuite';
const options = [
{
name: 'Date',
mask: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
placeholder: '25/09/1970'
},
{
name: 'Date with time',
mask: [
/\d/,
/\d/,
'/',
/\d/,
/\d/,
'/',
/\d/,
/\d/,
/\d/,
/\d/,
' ',
/\d/,
/\d/,
':',
/\d/,
/\d/,
' ',
/a|p/,
/m/
],
placeholder: '25/09/1970 12:00 pm'
},
{
name: 'CN phone number',
mask: ['1', /[3456789]/, /\d/, ' ', /\d/, /\d/, /\d/, /\d/, ' ', /\d/, /\d/, /\d/, /\d/],
placeholder: '138 1234 1234'
},
{
name: 'US phone number',
mask: ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
placeholder: '(555) 495-3947'
},
{
name: 'Credit Card',
mask: [
/\d/,
/\d/,
/\d/,
/\d/,
' ',
/\d/,
/\d/,
/\d/,
/\d/,
' ',
/\d/,
/\d/,
/\d/,
/\d/,
' ',
/\d/,
/\d/,
/\d/,
/\d/
],
placeholder: '4242 4242 4242 4242'
}
];
const placeholderChars = [
{
label: '\\u2000 (white space)',
value: '\u2000'
},
{
label: '_ (underscore)',
value: '_'
}
];
const ControlRow = ({ label, control, ...rest }) => (
{label}:
{control}
);
const App = () => {
const [option, setOption] = React.useState(options[0]);
const [value, setValue] = React.useState('');
const [guide, setGuide] = React.useState(true);
const [keepCharPositions, setKeepCharPositions] = React.useState(true);
const [placeholderChar, setPlaceholderChar] = React.useState('_');
const [showMask, setShowMask] = React.useState(false);
return (
} spacing={10} h={200}>
{
setOption(item);
setValue('');
}}
w={160}
/>
}
/>
}
/>
} />
}
/>
{
setShowMask(!showMask);
setValue('');
}}
/>
}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------ | ------------------------------------- | -------------------------------------------------------------------- |
| as | ElementType `('input')` | You can use a custom element type for this component |
| classPrefix | string `('input')` | The prefix of the component CSS class |
| defaultValue | string | Default value (uncontrolled) |
| disabled | boolean | Render the component in a disabled state |
| htmlSize | number | Sets the native HTML size attribute. |
| id | string | The HTML input id |
| inputRef | Ref | A ref that points to the input element |
| onChange | (value: string, event) => void | Callback function when value changes |
| plaintext | boolean | Render the input as plaintext. Shows placeholder when value is empty |
| readOnly | boolean | Render the component in a read-only state |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | An input can have different sizes |
| type | string `('text')` | HTML input type |
| value | string | Current value (controlled) |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------------- | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('input-group')` | The prefix of the component CSS class |
| disabled | boolean | Render the input group in a disabled state |
| inside | boolean | Sets the composition content internally |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | An input group can have different sizes |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ---------------------------- | ------------------------------------------- |
| classPrefix | string `('input-group-btn')` | The prefix of the component CSS class |
| ... | [ButtonProps][ButtonProps] | Extends all props from `` component |
[ButtonProps]: /components/button/#props
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------ | ---------------------------------------------------- |
| as | ElementType `('span')` | You can use a custom element type for this component |
| classPrefix | string `('input-group-addon')` | The prefix of the component CSS class |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------ | ------------------------------------------------------------------------------------------------------- |
| guide | boolean | In guide mode or no guide mode |
| keepCharPositions | boolean `(false)` | When `true`, adding or deleting characters will not affect the position of existing characters. |
| mask (\*) | array \| function | Used to define how to block user input. |
| placeholderChar | string `('_')` | The placeholder character represents the fillable spot in the mask |
| showMask | boolean | When the input value is empty, the mask is displayed as a placeholder instead of a regular placeholder. |
| ... | [InputProps][InputProps] | Extends all props from `` component. But does not have the `type` prop. |
[InputProps]: /components/input/#props
, flag: '🇺🇸' },
{ label: 'EUR - Euro', value: 'EUR', symbol: '€', flag: '🇪🇺' },
{ label: 'GBP - British Pound', value: 'GBP', symbol: '£', flag: '🇬🇧' },
{ label: 'JPY - Japanese Yen', value: 'JPY', symbol: '¥', flag: '🇯🇵' }
];
function App() {
const [currency, setCurrency] = React.useState(currencies[0]);
const renderMenu = ({ onClose, left, top, className }, ref) => {
return (
{currencies.map(currency => (
{
setCurrency(currency);
onClose();
}}
>
{currency.flag}
{currency.label}
))}
);
};
return (
{currency.value}
{currency.symbol}
{currency.value}
{currency.symbol}
);
}
ReactDOM.render(, document.getElementById('root'));
```
### With Tooltip
### Masked Input
MaskedInput is an input mask component. It can create input masks for phone numbers, dates, currencies, zip codes, percentages, emails, and almost anything.
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------ | ------------------------------------- | -------------------------------------------------------------------- |
| as | ElementType `('input')` | You can use a custom element type for this component |
| classPrefix | string `('input')` | The prefix of the component CSS class |
| defaultValue | string | Default value (uncontrolled) |
| disabled | boolean | Render the component in a disabled state |
| htmlSize | number | Sets the native HTML size attribute. |
| id | string | The HTML input id |
| inputRef | Ref | A ref that points to the input element |
| onChange | (value: string, event) => void | Callback function when value changes |
| plaintext | boolean | Render the input as plaintext. Shows placeholder when value is empty |
| readOnly | boolean | Render the component in a read-only state |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | An input can have different sizes |
| type | string `('text')` | HTML input type |
| value | string | Current value (controlled) |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------------- | ---------------------------------------------------- |
| as | ElementType `('div')` | You can use a custom element type for this component |
| classPrefix | string `('input-group')` | The prefix of the component CSS class |
| disabled | boolean | Render the input group in a disabled state |
| inside | boolean | Sets the composition content internally |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | An input group can have different sizes |
### ``
| Property | Type `(Default)` | Description |
| ----------- | ---------------------------- | ------------------------------------------- |
| classPrefix | string `('input-group-btn')` | The prefix of the component CSS class |
| ... | [ButtonProps][ButtonProps] | Extends all props from `` component |
[ButtonProps]: /components/button/#props
### ``
| Property | Type `(Default)` | Description |
| ----------- | ------------------------------ | ---------------------------------------------------- |
| as | ElementType `('span')` | You can use a custom element type for this component |
| classPrefix | string `('input-group-addon')` | The prefix of the component CSS class |
### ``
| Property | Type `(Default)` | Description |
| ----------------- | ------------------------ | ------------------------------------------------------------------------------------------------------- |
| guide | boolean | In guide mode or no guide mode |
| keepCharPositions | boolean `(false)` | When `true`, adding or deleting characters will not affect the position of existing characters. |
| mask (\*) | array \| function | Used to define how to block user input. |
| placeholderChar | string `('_')` | The placeholder character represents the fillable spot in the mask |
| showMask | boolean | When the input value is empty, the mask is displayed as a placeholder instead of a regular placeholder. |
| ... | [InputProps][InputProps] | Extends all props from `` component. But does not have the `type` prop. |
[InputProps]: /components/input/#props
================================================================================
# Components: Input Picker - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/input-picker/en-US/index.md
================================================================================
# InputPicker
Single item selector with text box input.
## Import
**Main import:**
```js
import { InputPicker } from 'rsuite';
```
**Individual import:**
```js
import InputPicker from 'rsuite/InputPicker';
// (Optional) Import component styles.
import 'rsuite/InputPicker/styles/index.css';
```
## Examples
### Basic
```js
import { InputPicker } from 'rsuite';
const data = [
'Eugenia',
'Bryan',
'Linda',
'Nancy',
'Lloyd',
'Alice',
'Julia',
'Albert',
'Louisa',
'Lester',
'Lola',
'Lydia',
'Hal',
'Hannah',
'Harriet',
'Hattie',
'Hazel',
'Hilda'
].map(item => ({ label: item, value: item }));
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { InputPicker, VStack } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Block
```js
import { InputPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Group
```js
import { InputPicker } from 'rsuite';
import { mockUsers } from './mock';
/**
* Data structure:
* [
* { firstLetter: 'A', name: 'Alan', firstName: 'Alan' },
* { firstLetter: 'B', name: 'Benson', firstName: 'Benson' },
* ]
*/
const data = mockUsers(100)
.map(item => {
const firstLetter = item.firstName[0].toUpperCase();
return { firstLetter, ...item };
})
.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter));
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Creatable
```js
import { InputPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({
label: item,
value: item,
role: Math.random() > 0.5 ? 'Owner' : 'Guest'
})
);
const App = () => (
<>
{
console.log(value, item);
}}
/>
{
console.log(value, item);
}}
/>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom
```js
import { InputPicker, HStack } from 'rsuite';
import { FaUserGroup, FaUser } from 'react-icons/fa6';
import { mockUsers } from './mock';
/**
* Data structure:
* [
* { firstLetter: 'A', name: 'Alan', firstName: 'Alan' },
* { firstLetter: 'B', name: 'Benson', firstName: 'Benson' },
* ]
*/
const data = mockUsers(100)
.map(item => {
const firstLetter = item.firstName[0].toUpperCase();
return { firstLetter, ...item };
})
.sort((a, b) => -b.firstLetter.localeCompare(a.firstLetter));
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
const renderOption = (label, item) => {
return (
{label}
);
};
const renderOptionGroup = (label, item) => {
return (
{label} - ({item.children.length})
);
};
const renderValue = (value, items) => {
return (
User: {value}
);
};
```
### Disabled and read only
```js
import { InputPicker, VStack, HStack, Text, Divider } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
}>
Disabled
Disabled option
ReadOnly
Plaintext
);
ReactDOM.render(, document.getElementById('root'));
```
### Async
```js
import { InputPicker, HStack, Loader } from 'rsuite';
const useUsers = (defaultUsers = []) => {
const [users, setUsers] = React.useState(defaultUsers);
const [loading, setLoading] = React.useState(false);
const featUsers = word => {
setLoading(true);
fetch(`https://api.github.com/search/users?q=${word}`)
.then(response => response.json())
.then(data => {
setUsers(data.items);
setLoading(false);
})
.catch(e => console.log('Oops, error', e));
};
return [users, loading, featUsers];
};
const App = () => {
const [users, loading, featUsers] = useUsers();
return (
{
if (loading) {
return (
);
}
return listbox;
}}
/>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
```js
import { InputPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => {
const [value, setValue] = React.useState(null);
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
On small screen devices, the selection list will be converted to a popup selector. To maintain the component's search functionality, this will only take effect when `searchable={false}` is set.
## Accessibility
### ARIA properties
- InputPicker has role `combobox`.
- Has the `aria-haspopup="listbox"` attribute to indicate that the combobox has a popup listbox.
- Has the `aria-expanded` attribute to indicate whether the listbox is open or not.
- Has the `aria-controls` attribute to indicate the ID of the listbox element.
- Has the `aria-activedescendant` attribute to indicate the ID of the focused option.
- When `label` is set, the `aria-labelledby` attribute is added to the combobox element and the listbox element and is set to the value of the `id` attribute of `label`.
### Keyboard interactions
- ↓ - Move focus to the next option.
- ↑ - Move focus to the previous option.
- Enter - Select the focused option.
- Esc - Close the listbox.
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------- |
| block | boolean | Render the component as a block element |
| caretAs | ElementType | Custom component for the caret icon |
| classPrefix | string `('picker')` | The prefix for the component CSS class |
| cleanable | boolean `(true)` | Whether the value can be cleared |
| container | HTMLElement\| (() => HTMLElement) | Sets the rendering container |
| creatable | boolean | Allow creating new options |
| data \* | [Option][item][] | The data for the component |
| defaultValue | string | Default value (uncontrolled) |
| disabled | boolean | Whether the component is disabled |
| disabledItemValues | string[] | Values of disabled items |
| groupBy | string | Key for grouping data items |
| labelKey | string `('label')` | Key for the label in data items |
| listboxMaxHeight | number `(320)` | Maximum height of the listbox |
| listProps | [ListProps][listprops] | Properties for virtualized lists |
| loading | boolean `(false)` | Whether to show a loading state |
| locale | [PickerLocaleType](/guide/i18n/#pickers) | Locale settings for component text |
| onChange | (value:string, event) => void | Callback fired when value changes |
| onClean | (event) => void | Callback fired when value is cleared |
| onClose | () => void | Callback fired when component closes |
| onCreate | (value: string, item: [Option][item], event) => void | Callback fired when a new option is created |
| onEnter | () => void | Callback fired before overlay transitions in |
| onEntered | () => void | Callback fired after overlay finishes transitioning in |
| onEntering | () => void | Callback fired as overlay begins to transition in |
| onExit | () => void | Callback fired right before overlay transitions out |
| onExited | () => void | Callback fired after overlay finishes transitioning out |
| onExiting | () => void | Callback fired as overlay begins to transition out |
| onGroupTitleClick | (event) => void | Callback fired when group header is clicked |
| onOpen | () => void | Callback fired when component opens |
| onSearch | (search:string, event) => void | Callback fired when search is performed |
| onSelect | (value:string, item: [Option][item] , event) => void | Callback fired when an item is selected |
| open | boolean | Whether the component is open |
| placeholder | ReactNode `('Select')` | Placeholder text |
| placement | [Placement](#code-ts-placement-code)`('bottomStart')` | The placement of the component |
| popupClassName | string | Custom CSS class for the popup |
| popupStyle | CSSProperties | Custom style for the popup |
| preventOverflow | boolean | Prevent floating element overflow |
| renderExtraFooter | () => ReactNode | Custom render function for extra footer |
| renderListbox | (listbox: ReactNode) => ReactNode | Custom render function for listbox |
| renderOption | (label: ReactNode, item: [Option][item]) => ReactNode | Custom render function for options |
| renderOptionGroup | (groupTitle: ReactNode, item: [Option][item]) => ReactNode | Custom render function for option groups |
| renderValue | (value:string, item: [Option][item],selected:ReactNode) => ReactNode | Custom render function for selected value |
| searchable | boolean `(true)` | Whether the component is searchable |
| searchBy | (keyword: string, label: ReactNode, item: [Option][item]) => boolean | Custom search function |
| shouldDisplayCreateOption | (searchKeyword: string, filteredData: InputOption[]) => boolean | Function to determine whether to display "Create option" |
| size | 'lg'\| 'md'\| 'sm'\| 'xs' `('md')` | Size of the component |
| sort | (isGroup: boolean) => (a: any, b: any) => number | Custom sort function for options |
| toggleAs | ElementType `('a')` | Custom element for the component |
| value | string | Current value (controlled) |
| valueKey | string `('value')` | Key for the value in data items |
| virtualized | boolean | Whether to use virtualized list |
#### `ts:Option`
```ts
interface Option {
/** The value of the option corresponds to the `valueKey` in the data. **/
value: V;
/** The content displayed by the option corresponds to the `labelKey` in the data. **/
label: ReactNode;
/**
* The data of the child option corresponds to the `childrenKey` in the data.
* Properties owned by tree structure components, such as TreePicker, Cascader.
*/
children?: Option[];
/**
* Properties of grouping functional components, such as CheckPicker, InputPicker
*/
groupBy?: string;
/**
* The children under the current node are loading.
* Used for components that have cascading relationships and lazy loading of children. E.g. Cascader, MultiCascader
*/
loading?: boolean;
}
```
#### `ts:Placement`
```ts
type Placement =
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd'
| 'auto'
| 'autoVerticalStart'
| 'autoVerticalEnd'
| 'autoHorizontalStart'
| 'autoHorizontalEnd';
```
#### `ts:ListProps`
```ts
interface ListProps {
/**
* Size of a item in the direction being windowed.
*/
itemSize?: number | ((index: number) => number);
/**
* Scroll offset for initial render.
*/
initialScrollOffset?: number;
/**
* Called when the items rendered by the list change.
*/
onItemsRendered?: (props: ListOnItemsRenderedProps) => void;
/**
* Called when the list scroll positions changes, as a result of user scrolling or scroll-to method calls.
*/
onScroll?: (props: ListOnScrollProps) => void;
}
```
[item]: #code-ts-option-code
[listprops]: #code-ts-list-props-code
================================================================================
# Components: Kbd - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/kbd/en-US/index.md
================================================================================
# Kbd
Kbd is a keyboard shortcut.
## Import
**Main import:**
```js
import { Kbd } from 'rsuite';
```
**Individual import:**
```js
import Kbd from 'rsuite/Kbd';
// (Optional) Import component styles.
import 'rsuite/Kbd/styles/index.css';
```
## Examples
### Default
```js
import { Kbd } from 'rsuite';
const App = () => Command + K;
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { Kbd, VStack } from 'rsuite';
const App = () => (
Command + KCommand + KCommand + KCommand + K
);
ReactDOM.render(, document.getElementById('root'));
```
### Function Keys
```js
import { Kbd, HStack } from 'rsuite';
const App = () => (
⌘⌥⇧⌃F12
);
ReactDOM.render(, document.getElementById('root'));
```
### Within Text
```js
import { Kbd, Text } from 'rsuite';
const App = () => (
Please press Command + K to open the keyboard.
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(Default)` | Description |
| ----------- | ------------------------------------- | -------------------------------------- |
| children | ReactNode | The content of the kbd. |
| classPrefix | string `('kbd')` | The prefix of the component CSS class. |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('md')` | The size of the kbd. |
================================================================================
# Components: Link - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/link/en-US/index.md
================================================================================
# Link
Used to create a link.
## Import
**Main import:**
```js
import { Link } from 'rsuite';
```
**Individual import:**
```js
import Link from 'rsuite/Link';
// (Optional) Import component styles.
import 'rsuite/Link/styles/index.css';
```
## Examples
### Default
```js
import { Link } from 'rsuite';
const App = () => {
return Default Link;
};
ReactDOM.render(, document.getElementById('root'));
```
### Disabled
```js
import { Link } from 'rsuite';
const App = () => {
return (
Disabled Link
);
};
ReactDOM.render(, document.getElementById('root'));
```
### External Link
Set the `external` prop on Link to open in a new tab/window with `rel="noopener noreferrer"`. Use `showAnchorIcon` to display an external link icon.
```js
import { Link, HStack } from 'rsuite';
const App = () => {
return (
External Link
External Link with Icon
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Custom Anchor Icon
```js
import { Link, HStack } from 'rsuite';
import { RiExternalLinkLine, RiLink } from 'react-icons/ri';
const App = () => {
return (
}>
External Link
}>
Default Link
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Underline
```js
import { Link, HStack } from 'rsuite';
const App = () => {
return (
Underline always
Underline hover
Underline not-hover
Underline never
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Within Text
```js
import { Link, Text } from 'rsuite';
const App = () => {
return (
This is an example paragraph demonstrating how to embed links within text.
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Routing Library
The Link component can be used with other routing libraries (such as Next.js, React Router) through the `as` prop. See the [Composition Guide](https://rsuitejs.com/guide/composition/#react-router-dom) for details.
```js
import { Link } from 'rsuite';
import NextLink from 'next/link';
const App = () => {
return (
Next Link
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type`(Default)` | Description |
| -------------- | --------------------------------------------- | --------------------------------------- |
| anchorIcon | ReactNode | The icon to be displayed after the link |
| as | ElementType | Custom element for component |
| children | ReactNode | The content of the link |
| classPrefix | string `('link')` | The prefix of the component CSS class |
| disabled | boolean | Whether the link is disabled |
| external | boolean | Whether it's an external link |
| href | string | The URL of the link |
| showAnchorIcon | boolean | Whether to display an anchor icon |
| target | string | The target attribute of the link |
| underline | 'always' \| 'hover' \| 'not-hover' \| 'never' | Underline style |
================================================================================
# Components: List - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/list/en-US/index.md
================================================================================
# List
The List component is used to display a group of data, suitable for presenting list-like content, and supports drag-and-drop sorting.
## Import
**Main import:**
```js
import { List } from 'rsuite';
```
**Individual import:**
```js
import List from 'rsuite/List';
// (Optional) Import component styles.
import 'rsuite/List/styles/index.css';
```
## Examples
### Basic
```js
import { List } from 'rsuite';
const messages = [
{
id: 1,
sender: 'Alice',
content: 'Hey, are we still meeting tomorrow?',
time: '2024-12-05 10:15'
},
{ id: 2, sender: 'Bob', content: 'Yes, let’s meet at 3 PM.', time: '2024-12-05 10:18' },
{ id: 3, sender: 'Charlie', content: 'Can you send me the report?', time: '2024-12-05 11:00' },
{ id: 4, sender: 'David', content: 'I will, no worries.', time: '2024-12-05 11:05' }
];
const App = () => (
{messages.map(message => (
{message.sender}: {message.content} ({message.time})
))}
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { List, SegmentedControl } from 'rsuite';
const data = ['Roses are red', 'Violets are blue', 'Sugar is sweet', 'And so are you'];
const App = () => {
const [size, setSize] = React.useState('sm');
return (
<>
{data.map((item, index) => (
{item}
))}
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Border
```js
import { List } from 'rsuite';
const App = () => (
Roses are redViolets are blueSugar is sweetAnd so are you
);
ReactDOM.render(, document.getElementById('root'));
```
### Hover
```js
import { List } from 'rsuite';
const App = () => (
Roses are redViolets are blueSugar is sweetAnd so are you
);
ReactDOM.render(, document.getElementById('root'));
```
### Sortable
`index` of List.Item is required.
```js
import { List } from 'rsuite';
const defaultData = [
{ text: 'Finish the project report' },
{ text: 'Attend team meeting at 3 PM' },
{ text: 'Buy groceries for the week' },
{ text: 'Call mom to check in' }
];
const App = () => {
const [data, setData] = React.useState(defaultData);
const handleSortEnd = ({ oldIndex, newIndex }) =>
setData(prvData => {
const moveData = prvData.splice(oldIndex, 1);
const newData = [...prvData];
newData.splice(newIndex, 0, moveData[0]);
return newData;
}, []);
return (
{data.map(({ text }, index) => (
{text}
))}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Collection Sort
Each `collection` is independent, `index` of List.Item is required. (be unique in the collection)
```js
import { List } from 'rsuite';
const defaultData = [
{ text: 'Apple iPhone 15', collection: 0, price: 999, status: 'In Stock' },
{ text: 'Samsung Galaxy S23', collection: 0, price: 849, status: 'Out of Stock' },
{ text: 'Google Pixel 8', collection: 0, price: 799, status: 'In Stock' },
{ text: 'Sony WH-1000XM5 Headphones', collection: 1, price: 350, status: 'In Stock' },
{ text: 'Bose QuietComfort 45', collection: 1, price: 329, status: 'In Stock' },
{ text: 'Beats Studio 3 Wireless Headphones', collection: 1, price: 299, status: 'Out of Stock' },
{ text: 'Dell XPS 13 Laptop', collection: 2, price: 1200, status: 'In Stock' },
{ text: 'MacBook Pro 16-inch', collection: 2, price: 2400, status: 'Out of Stock' },
{ text: 'HP Spectre x360', collection: 2, price: 1500, status: 'In Stock' },
{ text: 'Oculus Quest 2', collection: 3, price: 299, status: 'In Stock', disabled: true },
{ text: 'PlayStation VR', collection: 3, price: 399, status: 'Out of Stock' }
];
const colors = [
'#f0f8ff', // Light Blue for Phones
'#f5f5dc', // Light Beige for Headphones
'#fff0f5', // Lavender for Laptops
'#ffebcd' // Blanched Almond for VR
];
const App = () => {
const [data, setData] = React.useState(defaultData);
const handleSortEnd = ({ oldIndex, newIndex }) =>
setData(prvData => {
const moveData = prvData.splice(oldIndex, 1);
const newData = [...prvData];
newData.splice(newIndex, 0, moveData[0]);
return newData;
});
// Function to assign a background color based on collection
const getCollectionStyle = collection => {
return { backgroundColor: colors[collection], color: 'black' };
};
return (
{data.map(({ text, collection, disabled, status, price }, index) => (
{text} - ${price} - Status: {status}
))}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Fixed Item Sort
Based on `Collection Sort`, the items in the list are fixed in position during sorting.
```js
import { List } from 'rsuite';
const BrowserList = ['Chrome', 'Edge', 'FireFox', 'Safari'];
const App = () => {
const [data, setData] = React.useState(BrowserList);
const handleSortEnd = ({ oldIndex, newIndex }) =>
setData(prvData => {
const moveData = prvData.splice((oldIndex - 1) / 2, 1);
const newData = [...prvData];
newData.splice((newIndex - 1) / 2, 0, moveData[0]);
return newData;
}, []);
return (
{data.flatMap((browser, index) => [
{index + 1}
,
{browser}
])}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### List with Custom Item
```js
import { List, HStack, Text, Avatar } from 'rsuite';
const messages = [
{
id: 1,
sender: 'Alice',
content: 'Hey, are we still meeting tomorrow?',
time: '2024-12-05 10:15',
avatar: 'https://i.pravatar.cc/150?u=1'
},
{
id: 2,
sender: 'Bob',
content: 'Yes, let’s meet at 3 PM.',
time: '2024-12-05 10:18',
avatar: 'https://i.pravatar.cc/150?u=2'
},
{
id: 3,
sender: 'Charlie',
content: 'Can you send me the report?',
time: '2024-12-05 11:00',
avatar: 'https://i.pravatar.cc/150?u=3'
},
{
id: 4,
sender: 'David',
content: 'I will, no worries.',
time: '2024-12-05 11:05',
avatar: 'https://i.pravatar.cc/150?u=4'
}
];
const App = () => (
{messages.map(message => (
{message.sender}
{message.time}
{message.content}
))}
);
ReactDOM.render(, document.getElementById('root'));
```
### No Divider
```js
import { List, HStack, Text } from 'rsuite';
import PeoplesIcon from '@rsuite/icons/Peoples';
import LocationIcon from '@rsuite/icons/Location';
import EmailIcon from '@rsuite/icons/Email';
import GlobalIcon from '@rsuite/icons/Global';
const data = [
{
id: 1,
icon: ,
value: 'rsuite/team'
},
{
id: 2,
icon: ,
value: 'Shanghai, China'
},
{
id: 3,
icon: ,
value: john.doe@rsuitejs.com
},
{
id: 4,
icon: ,
value: rsuitejs.com
}
];
const App = () => (
{data.map(item => (
{item.icon}
{item.value}
))}
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description | Version |
| ------------------ | -------------------------------------------------- | ---------------------------------------------------- | ----------- |
| autoScroll | boolean `(true)` | Enables automatic scrolling when the list overflows | |
| bordered | boolean | Displays borders around the list items | |
| divider | boolean | Displays a divider between the list items | ![][5.75.0] |
| hover | boolean | Enables hover animation on list items | |
| onSort | (payload:[Payload](#code-ts-payload-code)) => void | Callback triggered when sorting ends | |
| onSortEnd | (payload:[Payload](#code-ts-payload-code)) => void | Callback triggered after the sorting operation ends | |
| onSortMove | (payload:[Payload](#code-ts-payload-code)) => void | Callback triggered when an item is moved in the list | |
| onSortStart | (payload:[Payload](#code-ts-payload-code)) => void | Callback triggered at the start of sorting | |
| pressDelay | number `(0)` | Delay before sorting is triggered after pressing | |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `(md)` | Defines the size of the list items | |
| sortable | boolean | Enables sorting functionality for the list items | |
| transitionDuration | number `(300)` | Duration (in milliseconds) of the sort animation | |
### ``
| Property | Type `(Default)` | Description |
| ---------- | ----------------------------------- | ------------------------------------------------------------------------ |
| collection | number \| string `(0)` | The collection identifier for the list item |
| disabled | boolean | Disables the item, preventing it from being moved |
| index \* | number | The unique index of the item within its collection, required for sorting |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `(md)` | Defines the size of the individual list item |
### `ts:Payload`
```ts
interface Payload {
collection: number | string;
node: HTMLElement;
newIndex: number;
oldIndex: number;
}
```
================================================================================
# Components: Loader - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/loader/en-US/index.md
================================================================================
# Loader
A component that provides state during data loading.
## Import
**Main import:**
```js
import { Loader } from 'rsuite';
```
**Individual import:**
```js
import Loader from 'rsuite/Loader';
// (Optional) Import component styles.
import 'rsuite/Loader/styles/index.css';
```
## Examples
### Basic
```js
import { Loader } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### With Content
```js
import { Loader } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { Loader } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Speed
```js
import { Loader } from 'rsuite';
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Center
```js
import { Loader, Placeholder } from 'rsuite';
const App = () => (
>
);
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA Roles
- Loader has `role` of `status`.
- When the Loader has a `content` attribute, the `aria-labelledby` attribute is set to the `id` of the `content` element.
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------- | ---------------------------------------------------- | ----------------------------------------------- |
| backdrop | boolean | Whether the background is displayed |
| center | boolean | Centered in the container |
| classPrefix | string `('loader')` | The prefix of the component CSS class |
| content | ReactNode | Custom descriptive text |
| inverse | boolean | An alternative dark visual style for the Loader |
| size | 'lg' \| 'md' \| 'sm' \| 'xs'`('md')` | Sets the loader dimensions |
| speed | 'fast' \| 'normal' \| 'slow' \| 'paused'`('normal')` | The speed at which the loader rotates |
| vertical | boolean | The icon is displayed vertically with the text |
================================================================================
# Components: Menu - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/menu/en-US/index.md
================================================================================
# Menu
A menu component that provides a list of options with support for icons, descriptions and keyboard shortcuts.
## Import
**Main import:**
```js
import { Menu } from 'rsuite';
```
**Individual import:**
```js
import Menu from 'rsuite/Menu';
// (Optional) Import component styles.
import 'rsuite/Menu/styles/index.css';
```
- `Menu` The container component that manages menu state.
- `Menu.Item` Menu option component supporting icons and descriptions.
- `Menu.Separator` A divider line to group menu items.
## Examples
### Basic
```js
import { Menu } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Shortcut
```js
import { Menu } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Icons
```js
import { Menu } from 'rsuite';
import { PageIcon, IdInfoIcon, FileDownloadIcon, DetailIcon } from '@rsuite/icons';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Description
```js
import { Menu } from 'rsuite';
import { PageIcon, IdInfoIcon, FileDownloadIcon, DetailIcon } from '@rsuite/icons';
const MenuIcon = ({ as: Component }) => (
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Separator
```js
import { Menu } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Popover Menu
```js
import { Button, Menu, Popover, Whisper } from 'rsuite';
const renderSpeaker = ({ onClose, className, ...rest }, ref) => {
const handleSelect = eventKey => {
onClose();
console.log(eventKey);
};
return (
);
};
const App = () => {
return (
File
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Routing Library
The `Menu.Item` component can be used with other routing libraries (such as Next.js, React Router) through the `as` prop. See the [Composition Guide](/guide/composition/#third-party-routing-library) for details.
```js
import Link from 'next/link';
import { Menu } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### `
);
const Brand = () => (
Brand
);
const MegaMenuFeatures = ({ onClose }) => {
const handleSelect = () => onClose();
const leftMenuItems = [
{ icon: IoBarChartOutline, description: 'Data visualization', children: 'Charts' },
{ icon: IoDocumentTextOutline, description: 'Input and data collection', children: 'Forms' },
{ icon: IoGridOutline, description: 'Data presentation', children: 'Tables' },
{ icon: IoLayersOutline, description: 'Popup dialogs', children: 'Modals' }
];
const rightMenuItems = [
{ icon: IoTerminalOutline, description: 'Command-line interface', children: 'CLI' },
{ icon: IoBrushOutline, description: 'UI/UX resources', children: 'Design Kit' },
{ icon: IoColorPaletteOutline, description: 'Customizable styles', children: 'Themes' },
{ icon: IoShapesOutline, description: 'Visual symbols', children: 'Icons' }
];
return (
FeaturesView all
);
};
const MegaMenuContact = ({ onClose }) => {
return (
Contact Us
Acme Corporation
Haidian District, Beijing123 Innovation AvenueTech Plaza, 15th Floor
Business Hours
Monday to Friday: 8 AM - 5 PMSaturday and Sunday: Closed
Contact Us
);
};
const MegaMenuResources = ({ onClose }) => {
const handleSelect = () => {
onClose();
};
return (
Resources
);
};
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With Popover Menu
Show additional navigation items using a popover menu.
```js
import { Navbar, Nav, Avatar, Badge, IconButton, Whisper, Popover, Menu } from 'rsuite';
import { IoLogoReact, IoNotifications } from 'react-icons/io5';
const Brand = () => (
Brand
);
const App = () => (
ProfileSettingsNotificationsSign out
}
>
);
ReactDOM.render(, document.getElementById('root'));
```
### With Drawer
Display navigation items in a drawer menu on small screens.
```js
import { Navbar, Menu, Avatar, Drawer } from 'rsuite';
import { IoLogoReact } from 'react-icons/io5';
const App = () => {
return (
{({ onClose }) => {
return (
<>
MenuDocsComponentsTools Brand
>
);
}}
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Responsive
The navigation bar supports responsive layouts and adapts to different screen sizes.
You can use the `showFrom` and `hideFrom` props to control the visibility at different breakpoints:
```jsx
// Hide on screens larger than 'xs'
{/* Content for small screens */}
// Hide on screens smaller than 'xs'
{/* Content for large screens */}
```
## Props
### ``
| Property name | Type `(Default)` | Description |
| ------------------ | ----------------------------------------------- | --------------------------------------------------------- |
| appearance | 'default' \| 'inverse' \| 'subtle'`('default')` | Navigation bar appearance |
| as | ElementType `('nav')` | Custom element type |
| classPrefix | string `('navbar')` | The prefix of the component CSS class |
| drawerOpen | boolean | Control the open state of the drawer menu ![][6.0.0] |
| onDrawerOpenChange | (open: boolean) => void | Callback when drawer menu opens or closes ![][6.0.0] |
### ``
| Property name | Type `(Default)` | Description |
| ------------- | ------------------------- | --------------------------- |
| as | ElementType `('a')` | Custom element type |
| children | ReactNode | Brand content |
| classPrefix | string `('navbar-brand')` | The prefix of the CSS class |
| href | string | The URL of the brand link |
### ``
![][6.0.0]
| Property name | Type `(Default)` | Description |
| ------------- | ------------------------------------------------------------------- | ------------------------------------ |
| as | ElementType `('div')` | Custom element type |
| children | ReactNode \| (({ onClose }: { onClose: () => void }) => ReactNode) | Content or render function with onClose callback |
| classPrefix | string `('navbar-content')` | The prefix of the CSS class |
| hideFrom | [Breakpoints][breakpoints] | Hide content at specified breakpoint |
| showFrom | [Breakpoints][breakpoints] | Show content at specified breakpoint |
### ``
![][6.0.0]
| Property name | Type `(Default)` | Description |
| ------------- | ---------------------------------------- | ----------------------------------------------------------- |
| as | ElementType `('button')` | Custom element type |
| classPrefix | string `('burger')` | The prefix of the CSS class |
| color | [Color][Color] \| CSSProperties['color'] | The color of the burger lines |
| lineThickness | number | The thickness of the burger lines |
| onToggle | (open: boolean) => void | Callback function that is called when the toggle is clicked |
| open | boolean | Whether the burger is in open (X) state |
### ``
![][6.0.0]
Extends [`Drawer`](/components/drawer)
#### `ts:Breakpoints`
```ts
type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
```
#### `ts:Color`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
```
[breakpoints]: #code-ts-breakpoints-code
[Color]: #code-ts-color-code
================================================================================
# Components: Notification - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/notification/en-US/index.md
================================================================================
# Notification
Used for system notifications. Generally used to push messages.
## Import
**Main import:**
```js
import { Notification } from 'rsuite';
```
**Individual import:**
```js
import Notification from 'rsuite/Notification';
// (Optional) Import component styles.
import 'rsuite/Notification/styles/index.css';
```
## Examples
### Basic
Default notification style.
```js
import { Notification } from 'rsuite';
const App = () => You have a new message, please check it.;
ReactDOM.render(, document.getElementById('root'));
```
### Types
Set different notification types using the `type` prop: `info`, `success`, `warning`, and `error`.
```js
import { Notification, VStack, Divider } from 'rsuite';
const App = () => (
<>
Without headerYou have a new message, please check it.
The email has been sent successfully, please check it in the mailbox.
Your mailbox capacity has exceeded 90%, please clean it up in time to avoid affecting normal
use.
The email failed to send, please try again later.With header
You have a new message, please check it.
The email has been sent successfully, please check it in the mailbox.
Your mailbox capacity has exceeded 90%, please clean it up in time to avoid affecting normal
use.
The email failed to send, please try again later.
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Closeable
Add a close button with the `closable` prop and handle the close event with `onClose` callback.
```js
import { Notification } from 'rsuite';
const App = () => (
<>
The email failed to send, please try again later.
>
);
ReactDOM.render(, document.getElementById('root'));
```
### With toaster
Demonstrates how to use the Notification component with `toaster` to display notification messages.
> **Note**: `useToaster` must be used inside a `CustomProvider`. If your application is not wrapped with `CustomProvider`, make sure to wrap your app with `` before using `useToaster`.
```js
import { Notification, useToaster, ButtonToolbar, SelectPicker, Button } from 'rsuite';
const App = () => {
const [type, setType] = React.useState('info');
const [placement, setPlacement] = React.useState('topStart');
const toaster = useToaster();
const message = (
>
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------- | ------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| activePage \* | number `(1)` | Current page number |
| boundaryLinks | boolean | Show border paging buttons 1 and pages |
| classPrefix | string `('pagination-group')` | The prefix of the component CSS class |
| disabled | boolean \| (eventKey: number) => boolean | Disabled component |
| ellipsis | boolean | Displays the ellipsis |
| first | boolean | Displays the first page |
| last | boolean | Displays the last page |
| layout | [LayoutType](#code-ts-layout-type-code)[] `(['pager'])` | Customize the layout of a paging component |
| limit | number `(30)` | The number of rows per page.Will use `total` and `limit` to calculate the number of pages |
| limitOptions | number[] `([30,50,100])` | Customizes the options of the rows per page select field. |
| linkAs | ElementType `(button)` | Customizes the element type for the component |
| linkProps | object | Additional props passed as-is to the underlying link for non-active items |
| locale | [PaginationLocale](/guide/i18n/#pagination) | Define localization settings to show component text in the user's regional language |
| maxButtons | number | Page buttons display the maximum number of |
| next | boolean | Displays the next page |
| onChangeLimit | (limit:number) => void; | Callback fired when the number of rows per page is changed |
| onChangePage | (page:number) => void; | Callback fired when the page is changed |
| prev | boolean | Displays the previous page |
| size | 'lg' \| 'md' \| 'sm' \| 'xs' `('sm')` | The size of the pagination component |
| total \* | number | The total number of rows. Generally obtained through the server |
### Type Definitions
#### `ts:LayoutType`
```ts
type LayoutType = 'total' | '-' | 'pager' | '|' | 'limit' | 'skip';
```
================================================================================
# Components: Panel - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/panel/en-US/index.md
================================================================================
# Panel
A content panel that supports collapsible, shadow, and border containers.
## Import
**Main import:**
```js
import { Panel, PanelGroup } from 'rsuite';
```
**Individual import:**
```js
import Panel from 'rsuite/Panel';
import PanelGroup from 'rsuite/PanelGroup';
// (Optional) Import component styles.
import 'rsuite/Panel/styles/index.css';
import 'rsuite/PanelGroup/styles/index.css';
```
## Examples
### Basic
```js
import { Panel, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With border
```js
import { Panel, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With shadow
```js
import { Panel, Placeholder } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Scroll shadows
```js
import { Panel, Placeholder } from 'rsuite';
const bodyProps = {
style: {
height: 300
}
};
const App = () => (
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Triggering events
`Whisper` provides a `trigger` props, which is used to control the display of `Popover` in different business scenarios. Props values include:
- `click`: It will be triggered when the element is clicked, and closed when clicked again.
- `contextMenu`: It will be triggered when you trigger contextMenu on the element.
- `focus`: It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's `tab` key.
- `hover`: Will be triggered when the cursor (mouse pointer) is hovering over the element.
- `active`: It is triggered when the element is activated.
- `none`: No trigger event, generally used when it needs to be triggered by a method.
```js
import { Popover, Whisper, Button, ButtonToolbar } from 'rsuite';
const speaker = (
}
>
Click me
)}
);
ReactDOM.render(, document.getElementById('root'));
```
### Used with Menu
```js
import { Popover, Whisper, Button, Menu } from 'rsuite';
const MenuPopover = React.forwardRef(({ onSelect, ...rest }, ref) => (
New File
New File with Current Profile
Download As...
Export PDF
Export HTML
Settings
About
));
const App = () => {
const ref = React.useRef();
function handleSelectMenu(eventKey, event) {
console.log(eventKey);
ref.current.close();
}
return (
}
>
File
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Hide arrow indicator
You can hide arrow indicator by setting `arrow` props to `false`;
```js
import { Popover, Whisper, Button } from 'rsuite';
const App = () => (
This is a Popover without arrow indicator}
>
Click
);
ReactDOM.render(, document.getElementById('root'));
```
### Follow cursor
You can enable the `Popover` to follow the cursor by setting `followCursor={true}`.
```js
import { Popover, Whisper, Button } from 'rsuite';
const App = () => (
This is a Popover that follow cursor}>
Hover me
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description |
| ----------- | -------------------- | -------------------------------------- |
| arrow | boolean `(true)` | Whether show the arrow indicator |
| children \* | ReactNode | The content of the component. |
| classPrefix | string `('popover')` | The prefix of the component CSS class. |
| title | ReactNode | The title of the component. |
| visible | boolean | The component is visible by default. |
| full | boolean | The content full the container |
### ``
| Property | Type `(Default)` | Description |
| --------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------ |
| container | HTMLElement \| (() => HTMLElement) | Sets the rendering container |
| controlId | string | Set the `id` on `` and `aria-describedby` on `` |
| defaultOpen | boolean | Whether to open the overlay by default |
| delay | number | Delay time (ms) Time |
| delayClose | number | Delay close time (ms) Time |
| delayOpen | number | Delay open time (ms) Time |
| enterable | boolean | Whether mouse is allowed to enter the floating layer of popover,when the value of `trigger` is set to`hover` |
| followCursor | boolean | Whether enable `speaker` to follow the cursor |
| onBlur | () => void | Lose Focus callback function |
| onClick | () => void | Click on the callback function |
| onClose | () => void | Callback fired when close component |
| onEnter | () => void | Callback fired before the overlay transitions in |
| onEntered | () => void | Callback fired after the overlay finishes transitioning in |
| onEntering | () => void | Callback fired as the overlay begins to transition in |
| onExit | () => void | Callback fired right before the overlay transitions out |
| onExited | () => void | Callback fired after the overlay finishes transitioning out |
| onExiting | () => void | Callback fired as the overlay begins to transition out |
| onFocus | () => void | Callback function to get focus |
| onOpen | () => void | Callback fired when open component |
| open | boolean | Whether to open the overlay |
| placement | [Placement](#code-ts-placement-code) `('right')` | Dispaly placement |
| preventOverflow | boolean | Prevent floating element overflow |
| speaker \* | Tooltip \| Popover \| ReactElement | Displayed component |
| trigger | [Trigger](#code-ts-trigger-code) `(['hover','focus'])` | Triggering events |
### Whisper Methods
Whisper provides several methods available via `ref` to programmatically control the overlay display and positioning. These methods are useful when you need to manually trigger overlay actions, such as:
- Showing/hiding tooltips based on business logic
- Updating overlay position after content changes
- Creating custom interaction logic
Get the component instance using `ref`:
```jsx
const whisperRef = useRef();
Hover me
```
| Method | Type Definition | Description |
| -------------- | -------------------------- | ------------------------------------------------------------------- |
| open | `(delay?: number) => void` | Manually open the overlay with an optional `delay` in milliseconds |
| close | `(delay?: number) => void` | Manually close the overlay with an optional `delay` in milliseconds |
| updatePosition | `() => void` | Manually update the overlay position when content changes |
```jsx
// Open overlay on button click
whisperRef.current?.open()}>Show Tooltip;
// Show overlay after data is loaded
useEffect(() => {
if (dataLoaded) {
whisperRef.current?.open(300); // Show after 300ms
}
}, [dataLoaded]);
// Update overlay position when content changes
const handleResize = useCallback(() => {
whisperRef.current?.updatePosition();
}, []);
```
### Type definitions
#### `ts:Trigger`
```ts
type Trigger =
| Array<'click' | 'contextMenu' | 'hover' | 'focus' | 'active'>
| 'click'
| 'contextMenu'
| 'hover'
| 'focus'
| 'active'
| 'none';
```
#### `ts:Placement`
```ts
type Placement =
| 'top'
| 'bottom'
| 'right'
| 'left'
| 'bottomStart'
| 'bottomEnd'
| 'topStart'
| 'topEnd'
| 'leftStart'
| 'leftEnd'
| 'rightStart'
| 'rightEnd'
| 'auto'
| 'autoVerticalStart'
| 'autoVerticalEnd'
| 'autoHorizontalStart'
| 'autoHorizontalEnd';
```
================================================================================
# Components: Progress - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/progress/en-US/index.md
================================================================================
# Progress
Display the current progress of an operation flow.
## Import
**Main import:**
```js
import { Progress } from 'rsuite';
```
**Individual import:**
```js
import Progress from 'rsuite/Progress';
// (Optional) Import component styles.
import 'rsuite/Progress/styles/index.css';
```
## Examples
### Basic
The default Progress component displays a horizontal progress bar.
```js
import { Progress, VStack } from 'rsuite';
const App = () => ;
ReactDOM.render(, document.getElementById('root'));
```
### Status
Use the `status` prop to indicate different states: 'active', 'success', or 'fail'.
```js
import { Progress, VStack } from 'rsuite';
const App = () => (
ActiveFailSuccess
);
ReactDOM.render(, document.getElementById('root'));
```
### Indeterminate
Use the `indeterminate` prop to display an animated loading state when the progress percentage is unknown. This creates a continuous animation effect to indicate that an operation is in progress.
```js
import { Progress } from 'rsuite';
const App = () => {
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Color
Customize the progress bar color with the `strokeColor` prop.
```js
import { Progress, VStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
Adjust the height of the progress bar using the `strokeWidth` prop. You can also customize the border radius with the `radius` prop.
```js
import { Progress, VStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Percent placement
Control the position of the percentage indicator with the `percentPlacement` prop. Options include 'start', 'end', 'insideStart', 'insideEnd', and 'insideCenter'.
```js
import { Progress, VStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Striped
Apply a striped effect to the progress bar using the `striped` prop. When combined with 'active' status, the stripes will animate.
```js
import { Progress, VStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Info Content
Use the `renderInfo` prop to customize the content displayed in the progress info area. This allows for more complex and informative displays beyond the default percentage.
```jsx
import { Progress, VStack, HStack } from 'rsuite';
import { FaCheckCircle } from 'react-icons/fa';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Multiple Sections
Use the `sections` prop to display multiple progress sections with different colors. This is useful for visualizing different parts of a process or comparing multiple values.
```jsx
import { Progress, VStack, HStack, Text } from 'rsuite';
const App = () => (
Macintosh HDUsed: 750 GB / 1 TB
);
ReactDOM.render(, document.getElementById('root'));
```
### Vertical
Display a vertical progress bar with the `vertical` prop. All other properties like status, color, and percent placement work with vertical progress bars as well.
```js
import { Progress, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type `(Default)` | Description | Version |
| ---------------- | ---------------------------------------------------------------------------- | ---------------------------------------- | ---------- |
| classPrefix | string `('progress-line')` | The prefix of the component CSS class | |
| indeterminate | boolean | Show indeterminate loading animation | ![][6.0.0] |
| percent | number `(0)` | Percent of progress | |
| percentPlacement | 'start' \| 'end' \| 'insideStart' \| 'insideEnd' \| 'insideCenter' `('end')` | The placement of the percent info | ![][6.0.0] |
| radius | number \| string | The radius of the progress bar | ![][6.0.0] |
| renderInfo | (percent: number, status?: 'success' \| 'fail' \| 'active') => ReactNode | Custom render function for info content | ![][6.0.0] |
| sections | [ProgressSection](#code-ts-progress-section-code)[] | Multiple sections with different colors | ![][6.0.0] |
| showInfo | boolean `(true)` | Show text | |
| status | 'success' \| 'fail' \| 'active' | Progress status | |
| striped | boolean | Whether to apply a striped effect | ![][6.0.0] |
| strokeColor | string | Line color | |
| strokeWidth | number | Line width | |
| trailColor | string | Trail color | |
| trailWidth | number | Trail width | |
| vertical | boolean | The progress bar is displayed vertically | |
| width | number | Circle diameter |
### `ts:ProgressSection`
```ts
interface ProgressSection {
/** Percent of this section */
percent: number;
/** Color of this section */
color: string;
/** Label of this section */
label?: React.ReactNode;
/** Tooltip of this section */
tooltip?: React.ReactNode;
}
```
================================================================================
# Components: Progress Circle - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/progress-circle/en-US/index.md
================================================================================
# ProgressCircle
Display circular progress for an operation.
## Import
**Main import:**
```js
import { ProgressCircle } from 'rsuite';
```
**Individual import:**
```js
import ProgressCircle from 'rsuite/ProgressCircle';
// (Optional) Import component styles.
import 'rsuite/ProgressCircle/styles/index.css';
```
## Examples
### Basic
A basic circular progress bar.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Status
Use the `status` prop to indicate different states: 'active', 'success', or 'fail'.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Color
Customize the progress bar color with the `strokeColor` prop.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
Adjust the thickness of the progress bar using the `strokeWidth` prop.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Gap
Customize the gap degree and position of the circular progress bar using the `gapDegree` and `gapPosition` props.
```js
import { ProgressCircle, VStack, HStack } from 'rsuite';
const App = () => (
'Top'}
/>
'Right'}
/>
'Bottom'}
/>
'Left'}
/>
'0'} />
'90'} />
'180'} />
'270'} />
);
ReactDOM.render(, document.getElementById('root'));
```
### Stroke Linecap
Control the end shape of the progress bar with the `strokeLinecap` prop. Options include 'round', 'square', and 'butt'.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Hide Info
Hide the percentage display in the center using the `showInfo` prop.
```js
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Custom Info Content
Use the `renderInfo` prop to customize the content displayed in the progress info area. This allows for more complex and informative displays beyond the default percentage.
```jsx
import { ProgressCircle, HStack, VStack, Text } from 'rsuite';
import { FaCheckCircle } from 'react-icons/fa';
const App = () => (
`Usage`} />
(
Usage{percent}%
)}
/>
(
{status === 'success' ? : `${percent}%`}
)}
/>
);
ReactDOM.render(, document.getElementById('root'));
```
### Multiple Sections
Use the `sections` prop to create a progress circle with multiple colored segments. Each section can have its own percentage and color.
```jsx
import { ProgressCircle, HStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
## Props
### ``
| Property | Type | Description | Version |
| ------------- | ------------------------------------------------------------------------ | ---------------------------------------- | ---------- |
| classPrefix | string `('progress')` | The prefix of the component CSS class | |
| gapDegree | number `(0)` | The gap degree of half circle, 0 ~ 360 | |
| gapPosition | 'right' \| 'top' \| 'bottom' \| 'left' `('top')` | Circular progress bar gap position | |
| percent | number `(0)` | Percent of progress | |
| renderInfo | (percent: number, status?: 'success' \| 'fail' \| 'active') => ReactNode | Custom render function for info content | ![][6.0.0] |
| showInfo | boolean `(true)` | Show text | |
| status | 'success' \| 'fail' \| 'active' | Progress status | |
| sections | { percent: number, color: string }[] | Multiple sections with different colors | ![][6.0.0] |
| strokeColor | string | Line color | |
| strokeLinecap | 'round' \| 'square' \| 'butt' `('round')` | The end of different types of open paths | |
| strokeWidth | number `(6)` | Line width | |
| trailColor | string | Trail color | |
| trailWidth | number `(6)` | Trail width | |
================================================================================
# Components: Radio - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/radio/en-US/index.md
================================================================================
# Radio
Radios are used when only one choice may be selected in a series of options.
## Import
**Main import:**
```js
import { Radio, RadioGroup } from 'rsuite';
```
**Individual import:**
```js
import Radio from 'rsuite/Radio';
import RadioGroup from 'rsuite/RadioGroup';
// (Optional) Import component styles.
import 'rsuite/Radio/styles/index.css';
import 'rsuite/RadioGroup/styles/index.css';
```
- `Radio` A radio button is a checkable input that when associated with other radio buttons, only one of which can be checked at a time.
- `RadioGroup` Radio Group allow users to select a single option from a list of mutually exclusive options.
## Examples
### Basic
```js
import { Radio, HStack } from 'rsuite';
const App = () => (
Radio Checked Radio
);
ReactDOM.render(, document.getElementById('root'));
```
### Disabled and read only
Use the `disabled` property to disable radio buttons, or the `readOnly` property to set them to read-only state.
```js
import { Radio, HStack, Text, Divider, VStack } from 'rsuite';
const App = () => (
}>
Disabled
Radio
Checked Radio
Read only
Radio
Checked Radio
Plaintext
Radio
Checked Radio
);
ReactDOM.render(, document.getElementById('root'));
```
### Colors
Set radio button colors using the `color` property.
```js
import { Radio, HStack } from 'rsuite';
const App = () => (
Red
Orange
Yellow
Green
Cyan
Blue
Violet
);
ReactDOM.render(, document.getElementById('root'));
```
### Radio Group
Use the `` component to group multiple radio buttons together and set a group name with the `name` property.
```js
import { Radio, RadioGroup } from 'rsuite';
const App = () => (
Radio ARadio BRadio CRadio D
);
ReactDOM.render(, document.getElementById('root'));
```
### Inline layout
Use the `inline` property to arrange radio buttons horizontally within a group.
```js
import { Radio, RadioGroup } from 'rsuite';
const App = () => (
Radio ARadio BRadio CRadio D
);
ReactDOM.render(, document.getElementById('root'));
```
### Controlled Radio Group
Implement controlled usage of radio groups with the `value` and `onChange` properties.
```js
import { Radio } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState('A');
return (
Radio ARadio BRadio CRadio D
);
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- RadioGroup `role` is `radiogroup`.
- Each Radio `role` is `radio`.
- If a Radio is checked, `aria-checked` is set to `true`.
- If a Radio is disabled, `aria-disabled` is set to `true`.
### Keyboard interaction
- → - Move focus to the next radio button. If focus is on the last radio button in the group, move to the first radio button.
- ← - Move focus to the previous radio button. If focus is on the first radio button in the group, move to the last radio button.
## Props
### ``
| Property | Type `(Default)` | Description | Version |
| -------------- | ------------------------------------------------ | ----------------------------------------------------------------------------- | ----------- |
| as | ElementType`(div)` | Custom element type for the component | |
| checked | boolean | Specifies whether the radio is selected | |
| color | [Color](#code-ts-color-code) | The color of the radio when checked | ![][5.56.0] |
| defaultChecked | boolean | Specifies the initial state: whether or not the radio is selected | |
| disabled | boolean | The disable of component | |
| inline | boolean | Inline layout | |
| inputProps | object | Attributes applied to the input element | |
| inputRef | ref | Pass a ref to the input element. | |
| name | string | Name to use for form | |
| onChange | (value: string, checked: boolean, event) => void | Callback function that has been checked for changes in state | |
| value | string | Value, corresponding to the value of the Radiogroup, to determine whether the | |
### ``
| Property | Type `(Default)` | Description |
| ------------ | ----------------------------- | ------------------------------------ |
| defaultValue | string | The default value (uncontrolled) |
| inline | boolean | Inline layout |
| name | string | Name to use for form |
| onChange | (value:string, event) => void | Callback function with value changed |
| value | string | The current value (controlled) |
### Type definitions
#### `ts:Color`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
```
================================================================================
# Components: Radio Tile - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/radio-tile/en-US/index.md
================================================================================
# RadioTile
A series of selectable tile components that behave like Radio.
## Import
**Main import:**
```js
import { RadioTile, RadioTileGroup } from 'rsuite';
```
**Individual import:**
```js
import RadioTile from 'rsuite/RadioTile';
import RadioTileGroup from 'rsuite/RadioTileGroup';
// (Optional) Import component styles.
import 'rsuite/RadioTile/styles/index.css';
import 'rsuite/RadioTileGroup/styles/index.css';
```
## Examples
### Basic
```js
import { RadioTile, RadioTileGroup } from 'rsuite';
import { Icon } from '@rsuite/icons';
import { VscLock, VscWorkspaceTrusted, VscRepo } from 'react-icons/vsc';
const App = () => (
} label="Private" value="private">
Project access must be granted explicitly to each user. If this project is part of a group,
access will be granted to members of the group.
} label="Internal" value="internal">
The project can be accessed by any logged in user except external users.
} label="Public" value="public">
The project can be accessed without any authentication.
);
ReactDOM.render(, document.getElementById('root'));
```
### Inline layout
```js
import { RadioTile, RadioTileGroup, useMediaQuery } from 'rsuite';
import { Icon } from '@rsuite/icons';
import { VscNotebookTemplate, VscRepoClone, VscFile } from 'react-icons/vsc';
const App = () => {
const [isInline] = useMediaQuery('xl'); // (min-width: 1200px)
return (
} label="Create blank project" value="blank">
Create a blank project to house your files, plan your work, and collaborate on code, among
other things.
}
label="Create from template"
value="template"
>
Create a project pre-populated with the necessary files to get you started quickly.
} label="Import project" value="import">
Migrate your data from an external source like GitHub, Bitbucket, or another instance of
GitLab.
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Disabled
```js
import { RadioTile, RadioTileGroup } from 'rsuite';
import { Icon } from '@rsuite/icons';
import { VscLock, VscWorkspaceTrusted, VscRepo } from 'react-icons/vsc';
const App = () => (
} label="Private" value="private" disabled>
Project access must be granted explicitly to each user. If this project is part of a group,
access will be granted to members of the group.
} label="Internal" value="internal" disabled>
The project can be accessed by any logged in user except external users.
} label="Public" value="public" disabled>
The project can be accessed without any authentication.
);
ReactDOM.render(, document.getElementById('root'));
```
### Accessibility
WAI-ARIA: https://www.w3.org/TR/wai-aria-practices/#radiobutton
- `RadioTile` has aria-checked set to `true` when it's checked. Otherwise, aria-checked is set to `false`.
## Props
### ``
| Property | Type `(Default)` | Description |
| -------------- | ---------------------------------------- | ------------------------------------------------------------------------------ |
| checked | boolean | Specifies whether the radio is selected |
| defaultChecked | boolean | Specifies the initial state: whether or not the radio is selected |
| disabled | boolean | The disable of component |
| name | string | Name to use for form |
| onChange | (value: string \| number, event) => void | Callback function that has been checked for changes in state |
| value | string \| number | Corresponding to the value of RadioTileGroup, determine whether it is selected |
### ``
| Property | Type `(Default)` | Description |
| ------------ | --------------------------------------- | ------------------------------------ |
| defaultValue | string \| number | The default value (uncontrolled) |
| disabled | boolean | The disable of component |
| inline | boolean | Inline layout |
| name | string | Name to use for form |
| onChange | (value:string \| number, event) => void | Callback function with value changed |
| value | string \| number | The current value (controlled) |
================================================================================
# Components: Rate - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/rate/en-US/index.md
================================================================================
# Rate
A rating indicates user interest in content.
## Import
**Main import:**
```js
import { Rate } from 'rsuite';
```
**Individual import:**
```js
import Rate from 'rsuite/Rate';
// (Optional) Import component styles.
import 'rsuite/Rate/styles/index.css';
```
## Examples
### Basic
### Sizes
The size of the rate component
### Color
The color of the rate component. Supports both preset theme colors and custom colors (hex, rgb, etc.).
### Half Star
### Vertical direction
Direction when half select
### Hover feedback
### Disabled and read only
### Characters
You can use other icons, emoji, numbers, Chinese or other custom patterns
### Customized rates
When there are multiple levels of rating, you can customize the character displayed at each level, but you need to implement this yourself
### Fractional ratings
### Advanced rating
## Accessibility
WAI tutorial: https://www.w3.org/WAI/tutorials/forms/custom-controls/#a-star-rating
## Props
### ``
| Property | Type `(Default)` | Description |
| --------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------ |
| allowHalf | boolean`(false)` | Whether to support half option |
| character | ReactNode | custom character |
| cleanable | boolean`(true)` | Whether clear is supported |
| defaultValue | number`(0)` | The default value (uncontrolled) |
| disabled | boolean`(false)` | Disabled,Cannot interact when value is true |
| max | number`(5)` | Maximum score |
| renderCharacter | (value: number) => ReactNode | Customize the render character function |
| readOnly | boolean | Whether it is read-only, if true, no interaction is possible |
| size | [Size](#code-ts-size-code) \| number \| string | Set component size |
| color | [Color](#code-ts-color-code) \| CSSProperties['color'] | Set component color. Supports preset theme colors and custom colors (hex, rgb, etc.) |
| value | number | The current value (controlled) |
| vertical | boolean`(false)` | direction when half select |
| onChange | (value: number, event) => void | Callback function that changes value |
| onChangeActive | (value: number, event) => void | Callback function that is fired when the hover state changes. |
#### `ts:Color`
```ts
type Color = 'red' | 'orange' | 'yellow' | 'green' | 'cyan' | 'blue' | 'violet';
```
#### `ts:Size`
```ts
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
```
================================================================================
# Components: Segmented Control - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/segmented-control/en-US/index.md
================================================================================
# SegmentedControl
SegmentedControl is used to offer multiple exclusive options.
## Import
**Main import:**
```js
import { SegmentedControl } from 'rsuite';
```
**Individual import:**
```js
import SegmentedControl from 'rsuite/SegmentedControl';
// (Optional) Import component styles.
import 'rsuite/SegmentedControl/styles/index.css';
```
## Examples
### Basic
```js
import { SegmentedControl } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Sizes
```js
import { SegmentedControl, VStack } from 'rsuite';
const App = () => {
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'];
const data = [
{ label: 'Day', value: 'day' },
{ label: 'Week', value: 'week' },
{ label: 'Month', value: 'month' },
{ label: 'Quarter', value: 'quarter' },
{ label: 'Year', value: 'year' }
];
return (
{sizes.map(size => (
))}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Disabled
Disabled state of the SegmentedControl.
```js
import { SegmentedControl, VStack } from 'rsuite';
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Indicator Appearance
SegmentedControl supports two indicator styles: Pill (default) and Underline.
```js
import { SegmentedControl, VStack, Text } from 'rsuite';
const App = () => (
PillUnderline
);
ReactDOM.render(, document.getElementById('root'));
```
### With Icons
Enhance options with icons for better visual recognition.
```js
import { SegmentedControl, HStack } from 'rsuite';
import { BsViewList, BsCalendar, BsCalendar3 } from 'react-icons/bs';
const data = [
{
label: (
Day
),
value: 'day'
},
{
label: (
Week
),
value: 'week'
},
{
label: (
Month
),
value: 'month'
}
];
const App = () => {
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
### Controlled
Controlled mode of SegmentedControl using `value` and `onChange` props.
```js
import { SegmentedControl, VStack, Text } from 'rsuite';
const App = () => {
const [value, setValue] = React.useState('all');
return (
setValue(value)}
data={[
{ label: 'All', value: 'all' },
{ label: 'Drafts', value: 'drafts' },
{ label: 'Published', value: 'published' },
{ label: 'Archived', value: 'archived' }
]}
/>
Selected value: {value}
);
};
ReactDOM.render(, document.getElementById('root'));
```
### Block
Display SegmentedControl as a block element that fills the width of its container.
```js
import { SegmentedControl } from 'rsuite';
const App = () => {
const data = [
{ label: 'Day', value: 'day' },
{ label: 'Week', value: 'week' },
{ label: 'Month', value: 'month' },
{ label: 'Quarter', value: 'quarter' },
{ label: 'Year', value: 'year' }
];
return ;
};
ReactDOM.render(, document.getElementById('root'));
```
## Accessibility
### ARIA properties
- SegmentedControl `role` is `radiogroup`.
- Each segment `role` is `radio`.
- If a segment is selected, `aria-checked` is set to `true`.
### Keyboard interaction
- → or ↓ - Move focus to the next segment, when the focus is on the last segment in the group, move to the first segment.
- ← or ↑ - Move focus to the previous segment. When the focus is on the first segment in the group, move to the last segment.
## Props
### ``
| Property | Type `(Default)` | Description |
| ------------ | ----------------------------------------------------------------- | -------------------------------------------- |
| block | boolean | Display as block and fit container width |
| data | [SegmentedItemDataType](#code-ts-segmented-item-data-type-code)[] | Data of segmented items |
| defaultValue | string \| number | Default value |
| disabled | boolean | Whether the component is disabled |
| indicator | 'pill' \| 'underline' (`'pill'`) | The indicator style of the segmented control |
| name | string | Name to use for form |
| onChange | (value: string \| number, event) => void | Callback fired when the value changes |
| size | [Size](#code-ts-size-code) `('md')` | A segmented control can have different sizes |
| value | string \| number | Value (controlled) |
### Type Definitions
#### `ts:SegmentedItemDataType`
```ts
interface SegmentedItemDataType {
/** The label of the item */
label: React.ReactNode;
/** The value of the item */
value: string | number;
}
```
#### `ts:Size`
```ts
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
```
================================================================================
# Components: Select Picker - Main Documentation
File: https://github.com/rsuite/rsuite/blob/main/docs/pages/components/select-picker/en-US/index.md
================================================================================
# SelectPicker
For a single data selection, support grouping.
## Import
**Main import:**
```js
import { SelectPicker } from 'rsuite';
```
**Individual import:**
```js
import SelectPicker from 'rsuite/SelectPicker';
// (Optional) Import component styles.
import 'rsuite/SelectPicker/styles/index.css';
```
## Examples
### Basic
```js
import { SelectPicker, VStack } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### With a label
```js
import { SelectPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Appearance
```js
import { SelectPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Size
```js
import { SelectPicker, VStack } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const styles = { width: 224, display: 'block', marginBottom: 10 };
const App = () => (
);
ReactDOM.render(, document.getElementById('root'));
```
### Block
```js
import { SelectPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
<>
>
);
ReactDOM.render(, document.getElementById('root'));
```
### Loading state
When the picker is loading, a spinner is displayed to indicate the loading state.
Clicking a loading picker won't open its options menu.
```js
import { SelectPicker } from 'rsuite';
const data = ['Eugenia', 'Bryan', 'Linda', 'Nancy', 'Lloyd', 'Alice', 'Julia', 'Albert'].map(
item => ({ label: item, value: item })
);
const App = () => (
<>