Skip to content

Commit 2d8ec98

Browse files
committed
docs: document placeholder prop for text input and prompt
1 parent a3c9fea commit 2d8ec98

4 files changed

Lines changed: 58 additions & 15 deletions

File tree

docs/pages/docs/components/prompt.mdx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Property } from '../../../components/Property'
1111
```lua
1212
n.prompt({
1313
prefix = " > ",
14+
placeholder = "Enter a command",
1415
border_label = {
1516
text = "Command",
1617
align = "center",
@@ -25,31 +26,51 @@ n.prompt({
2526

2627
#### value
2728

28-
<Property
29+
<Property
2930
types={["string"]}
3031
/>
3132

3233
#### prefix
3334

34-
<Property
35+
<Property
3536
types={["string"]}
3637
/>
3738

39+
#### placeholder
40+
41+
> Optional placeholder text to show when the input is empty.
42+
> Can be a string, a single virtual text chunk, or a list of virtual text chunks.
43+
44+
<Property
45+
defaultValue='nil'
46+
types={['string', '{ [1]: string, [2]: string }[]', 'nil']}
47+
/>
48+
49+
A virtual text chunk is a tuple-like table where the first element
50+
is the text and the second element is the highlight group.
51+
52+
```lua
53+
local placeholder = {
54+
{ "Hello", "Comment" },
55+
{ "World", "String" },
56+
}
57+
```
58+
3859
#### on_change
3960

40-
<Property
61+
<Property
4162
types={['fun(value: string, component: Prompt): nil']}
4263
/>
4364

4465
#### on_submit
4566

46-
<Property
67+
<Property
4768
types={['fun(value: string, component: Prompt): nil']}
4869
/>
4970

5071
#### submit_key
5172

52-
<Property
73+
<Property
5374
defaultValue="<CR>"
5475
types={["string[]", "string"]}
5576
/>

docs/pages/docs/components/text-input.mdx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { Property } from '../../../components/Property'
33

44
## TextInput
55

6-
`TextInput` is a component that allows you to enter any text.
6+
`TextInput` is a component that allows you to enter any text.
77

88
![](/gifs/text-input-1.gif)
99

1010
### Usage Example
1111

1212
```lua
13-
local signal = n.create_signal({
13+
local signal = n.create_signal({
1414
value = "hello world",
1515
})
1616

@@ -20,6 +20,7 @@ n.text_input({
2020
size = 1,
2121
value = signal.value,
2222
border_label = "Description",
23+
placeholder = "Enter a description",
2324
max_lines = 5,
2425
on_change = function(value, component)
2526
signal.value = value
@@ -38,7 +39,7 @@ n.text_input({
3839

3940
### Properties
4041

41-
#### autoresize
42+
#### autoresize
4243

4344
<Property
4445
defaultValue="false"
@@ -47,20 +48,40 @@ n.text_input({
4748

4849
#### max_lines
4950

50-
<Property
51+
<Property
5152
types={['number']}
5253
/>
5354

5455
#### value
5556

56-
<Property
57+
<Property
5758
defaultValue='""'
5859
types={['string']}
5960
/>
6061

62+
#### placeholder
63+
64+
> Optional placeholder text to show when the input is empty.
65+
> Can be a string, a single virtual text chunk, or a list of virtual text chunks.
66+
67+
<Property
68+
defaultValue='nil'
69+
types={['string', '{ [1]: string, [2]: string }[]', 'nil']}
70+
/>
71+
72+
A virtual text chunk is a tuple-like table where the first element
73+
is the text and the second element is the highlight group.
74+
75+
```lua
76+
local placeholder = {
77+
{ "Hello", "Comment" },
78+
{ "World", "String" },
79+
}
80+
```
81+
6182
#### on_change
6283

63-
<Property
84+
<Property
6485
types={['fun(value: string, component: TextInput): nil']}
6586
/>
6687

lua/nui-components/prompt.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Prompt:_attach_change_listener()
4646
self:set_current_value(value)
4747
props.on_change(value, self)
4848

49-
self:_update_placeholder(self:get_current_value() == "")
49+
self:_update_placeholder()
5050

5151
if prefix_length > 0 then
5252
vim.schedule(function()

lua/nui-components/text-input.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function TextInput:prop_types()
5757
}
5858
end
5959

60-
function TextInput:_update_placeholder(show)
60+
function TextInput:_update_placeholder()
61+
local show = self:get_current_value() == ""
6162
local props = self:get_props()
6263
local placeholder = props.placeholder
6364
if show and placeholder and placeholder ~= "" then
@@ -96,7 +97,7 @@ function TextInput:_attach_change_listener()
9697
self:set_current_value(value)
9798
props.on_change(value, self)
9899

99-
self:_update_placeholder(self:get_current_value() == "")
100+
self:_update_placeholder()
100101

101102
if props.autoresize then
102103
self._private.text_input_signal.size = math.max(#lines, self._private.text_input_initial_size)
@@ -216,7 +217,7 @@ end
216217

217218
function TextInput:on_mount()
218219
self:_attach_change_listener()
219-
self:_update_placeholder(self:get_current_value() == "")
220+
self:_update_placeholder()
220221
end
221222

222223
return TextInput

0 commit comments

Comments
 (0)