You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/pages/ShorthandProps.mdx
+51-15Lines changed: 51 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,8 +19,19 @@ There are several forms of shorthand values that can be provided, but all of the
19
19
Each component's shorthand has an associated default element type. For example, by default, there is `<Icon />` element rendered for `Button`'s icon shorthand. It is possible to customize props of this default element by providing props object as shorthand value:
20
20
21
21
```jsx
22
-
// 💡 'color' and 'name' will be used as <Icon /> element's props
{/* 💡 you can also add handlers and any DOM props to shorthands */}
26
+
<Input
27
+
action={{
28
+
icon:'search',
29
+
onClick: () =>console.log('An action was clicked!'),
30
+
}}
31
+
actionPosition='left'
32
+
placeholder='Search...'
33
+
/>
34
+
</>
24
35
```
25
36
26
37
## String as value
@@ -52,7 +63,11 @@ This works because `name` is the default prop of shorthand's `<Icon />` element.
52
63
It is also possible to pass falsy values (`false`, `null` or `undefined`) - in that case there will be nothing rendered for the component's shorthand.
53
64
54
65
```jsx
55
-
<Dropdown icon={null} />
66
+
<>
67
+
{/* 💡 hides a toogle icon in `Dropdown` */}
68
+
<Dropdown icon={null} />
69
+
<Dropdown icon={false} />
70
+
</>
56
71
```
57
72
58
73
## React Element as value
@@ -68,9 +83,9 @@ There are cases where it might be necessary to customize the element tree that w
68
83
<Message.Content>
69
84
There is a very important caveat here, though: whenever React Element is directly used as a
70
85
shorthand value, all props that Semantic UI React has created for the shorthand's Component will
71
-
be spread on the passed element. This means that the provided element should be able to handle props
72
-
- while this requirement is satisfied for all SUIR components, you should be aware of that when
73
-
either HTML or any third-party elements are provided.
86
+
be spread on the passed element. This means that the provided element should be able to handle
87
+
props - while this requirement is satisfied for all SUIR components, you should be aware of that
88
+
when either HTML or any third-party elements are provided.
74
89
</Message.Content>
75
90
</Message>
76
91
@@ -82,26 +97,47 @@ Due to this limitation, you should strive to use other options for shorthand val
82
97
83
98
However, there still might be cases where it would be impossible to use the object form of the shorthand value - for example, you might want to render some custom elements tree for the shorthand. In that case, function value should be used.
84
99
85
-
## Function as value
100
+
## Render props via `children`
86
101
87
-
Providing function as a shorthand value is the most involving but, at the same time, the most powerful option for customizing component's shorthand. The only requirements for this function are:
102
+
Providing function as a shorthand value is the most involving but, at the same time, the most powerful option for customizing component's shorthand. It should return React Element as a result or `null`.
Thus, in its simplest form, it could be used the following way:
114
+
### Customizing rendered shorthand
115
+
116
+
There is another use case when render function is very useful for - this is the case where custom element's tree should be rendered for the shorthand. As you might recall, there is a problem that might happen when React Element is provided directly as shorthand value - in that case, props are not propagated to rendered. In order to avoid that the following strategy should be considered:
There is another use case when render function is very useful for - this is the case where custom element's tree should be rendered for the shorthand. As you might recall, there is a problem that might happen when React Element is provided directly as shorthand value - in that case, props are not propagated to rendered. In order to avoid that the following strategy should be considered:
127
+
<Messagewarning>
128
+
This usage is deprecated and will be removed in v3, please use render props instead.
129
+
</Message>
130
+
131
+
Providing function as a shorthand value is the most involving but, at the same time, the most powerful option for customizing component's shorthand. The only requirements for this function are:
132
+
133
+
- it should finish synchronously
134
+
- it should return React Element as a result
135
+
136
+
Thus, in its simplest form, it could be used the following way:
`Warning: There is a deprecated shorthand function usage for "${Component}". It is deprecated and will be removed in v3 release. Please follow our upgrade guide: https://github.com/Semantic-Org/Semantic-UI-React/pull/4029`,
0 commit comments