Skip to content

Commit 0e3a9a6

Browse files
committed
docs
1 parent 9322548 commit 0e3a9a6

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

docs/data/material/migration/upgrade-to-v9/upgrade-to-v9.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,29 @@ in the ButtonBase keyboard handlers. This is actually the expected behavior.
6565

6666
#### Event handlers on disabled non-native buttons
6767

68-
When ButtonBase renders a non-native element like a `<span>`, keyboard event handlers will no longer run when the component is disabled.
68+
When ButtonBase renders a non-native element like a `<span>`, keyboard and click event handlers will no longer run when the component is disabled.
69+
70+
#### Replacing native button elements with non-interactive elements
71+
72+
The `nativeButton` prop is available on `<ButtonBase>` and all button-like components to ensure that they are rendered with the correct HTML attributes before hydration, for example during server-side rendering. This should be specified when when passing a React component to the `component` prop of a button-like component. This should be specified if the custom component either replaces the default rendered element:
73+
74+
- From a native `<button>` to a non-interactive element like a `<div>`, or
75+
- From a non-button like a `<div>` to a native `<button>`
76+
77+
```jsx
78+
const CustomButton = React.forwardRef(function CustomButton(props, ref) {
79+
return <div ref={ref} {...props} />;
80+
})
81+
82+
<Button component={CustomButton} nativeButton={false}>
83+
OK
84+
</Button>
85+
```
86+
87+
A warning will be shown in development mode if the `nativeButton` prop is incorrectly omitted, or if the resolved element
88+
does not match the value of the prop.
89+
90+
The prop can be used for: `<ButtonBase>`, `<Button>`, `<Fab>`, `<IconButton>`, `<ListItemButton>`, `<MenuItem>`, `<StepButton>`, `<Tab>`, `<ToggleButton>`, `<AccordionSummary>`, `<BottomNavigationAction>`, `<CardActionArea>`, `<TableSortLabel>` and `<PaginationItem>`.
6991

7092
### Autocomplete
7193

packages/mui-material/src/ButtonBase/useButtonBase.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ export default function useButtonBase(
187187

188188
// A helper for event handlers to determine whether to use browser-defined keyboard activation
189189
// for native elements like <button> and <a href>, or synthesize Enter/Space clicks for non-native
190-
// elements like `<div role="button">`
190+
// elements like `<div role="button">`.
191+
// This is UNSAFE TO USE outside of event handers, e.g. in render.
191192
const hasNativeKeyboardActivation = React.useCallback(() => {
192193
const root = rootRef.current;
193194

0 commit comments

Comments
 (0)