mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 06:35:39 +00:00
plugin: Hide placeholder inputs when focused
This commit is contained in:
@@ -13,12 +13,27 @@ local RoundBox = Assets.Slices.RoundBox
|
|||||||
local TEXT_SIZE = 22
|
local TEXT_SIZE = 22
|
||||||
local PADDING = 8
|
local PADDING = 8
|
||||||
|
|
||||||
local function FormTextInput(props)
|
local FormTextInput = Roact.Component:extend("FormTextInput")
|
||||||
local value = props.value
|
|
||||||
local placeholderValue = props.placeholderValue
|
function FormTextInput:init()
|
||||||
local onValueChange = props.onValueChange
|
self:setState({
|
||||||
local layoutOrder = props.layoutOrder
|
focused = false,
|
||||||
local width = props.width
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function FormTextInput:render()
|
||||||
|
local value = self.props.value
|
||||||
|
local placeholderValue = self.props.placeholderValue
|
||||||
|
local onValueChange = self.props.onValueChange
|
||||||
|
local layoutOrder = self.props.layoutOrder
|
||||||
|
local width = self.props.width
|
||||||
|
|
||||||
|
local shownPlaceholder
|
||||||
|
if self.state.focused then
|
||||||
|
shownPlaceholder = ""
|
||||||
|
else
|
||||||
|
shownPlaceholder = placeholderValue
|
||||||
|
end
|
||||||
|
|
||||||
return e("ImageLabel", {
|
return e("ImageLabel", {
|
||||||
LayoutOrder = layoutOrder,
|
LayoutOrder = layoutOrder,
|
||||||
@@ -41,13 +56,23 @@ local function FormTextInput(props)
|
|||||||
TextXAlignment = Enum.TextXAlignment.Center,
|
TextXAlignment = Enum.TextXAlignment.Center,
|
||||||
TextSize = TEXT_SIZE,
|
TextSize = TEXT_SIZE,
|
||||||
Text = value,
|
Text = value,
|
||||||
PlaceholderText = placeholderValue,
|
PlaceholderText = shownPlaceholder,
|
||||||
PlaceholderColor3 = Theme.AccentLightColor,
|
PlaceholderColor3 = Theme.AccentLightColor,
|
||||||
TextColor3 = Theme.AccentColor,
|
TextColor3 = Theme.AccentColor,
|
||||||
|
|
||||||
[Roact.Change.Text] = function(rbx)
|
[Roact.Change.Text] = function(rbx)
|
||||||
onValueChange(rbx.Text)
|
onValueChange(rbx.Text)
|
||||||
end,
|
end,
|
||||||
|
[Roact.Event.Focused] = function()
|
||||||
|
self:setState({
|
||||||
|
focused = true,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
[Roact.Event.FocusLost] = function()
|
||||||
|
self:setState({
|
||||||
|
focused = false,
|
||||||
|
})
|
||||||
|
end,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user