Skip to content

Commit

Permalink
[docs] New API design rule disabled > disable (mui#34972)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
  • Loading branch information
2 people authored and the-mgi committed Nov 17, 2022
1 parent da8f607 commit f398cf0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions docs/data/material/guides/api/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,23 @@ Nested components inside a component have:

### Prop naming

The name of a boolean prop should be chosen based on the **default value**. This choice allows:
- **Boolean**

- the shorthand notation. For example, the `disabled` attribute on an input element, if supplied, defaults to `true`:
- The default value of a boolean prop should be `false`. This allows for better shorthand notation. Consider an example of an input that is enabled by default. How should you name the prop that controls this state? It should be called `disabled`:

```jsx
<Input enabled={false} />
<Input disabled />
```
```jsx
<Input enabled={false} />
<Input disabled />
```

- If the name of the boolean is a single word, it should be an adjective or a noun rather than a verb. This is because props describe _states_ and not _actions_. For example an input prop can be controlled by a state, which wouldn't be described with a verb:

```jsx
const [disabled, setDisabled] = React.useState(false);

- developers to know what the default value is from the name of the boolean prop. It's always the opposite.
<Input disable={disabled} />
<Input disabled={disabled} />
```

### Controlled components

Expand Down

0 comments on commit f398cf0

Please sign in to comment.