NumericInput
Legacy address for preview.2 documentation. Use the versioned page. The API is the same.
Optional app library · SDK 0.1.0-preview.2.
Offer a bounded number field with decrease/increase buttons. Keep this source library’s private support files with it; use only the public NumericInput import.
Copy the SDK’s complete Examples/numeric-input folder to a new application folder outside the SDK. Keep its Vendor files, lui.json, module lock and SDK pin together. See library setup.
Import require("@LuiUI/NumericInput") after the project declares that library. An import copied into a basic starter is not enough.
Example
Section titled “Example”Replace Src/Main.luau in that prepared project with this complete file.
local Window = Instance.new("Window", {Title = "Library example", Size = UDim2.fromOffset(640, 300)})local Status = Instance.new("TextLabel", {Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 190), Size = UDim2.fromOffset(600, 72)})local NumericInput = require("@LuiUI/NumericInput")local Zoom = NumericInput.New(Window, {Value = 100, Minimum = 25, Maximum = 400, Step = 25, Label = "Zoom percent", OnChanged = function(Value) Status.Text = "Zoom: " .. Value .. "%" end})Zoom.View.Position = UDim2.fromOffset(16, 16)Zoom.View.Size = UDim2.fromOffset(300, 36)Window.Destroying:Connect(function() Zoom:Dispose() end)Window.Visible = trueExpected result: A number field and two step buttons update the zoom value. This is a source component built from ordinary LUI controls, not a new core Instance class.
Functions
Section titled “Functions”NumericInput.New(Parent: Instance, Options: Options?): ControllerBehavior and limits
Section titled “Behavior and limits”NumericInput composes existing Frame, TextBox and TextButton Instances. View, Input, Decrease and Increase expose these real LUI controls for application styling. The controller table is frozen. Layout uses a 36-unit height and two 36-unit buttons; applications own sizing and their surrounding responsive layout.
Options must be a plain table with only Value, Minimum, Maximum, Step, Label and OnChanged. Omitted bounds default to 0–100, step to 1 and value to the minimum. Bounds/values are finite, with -1e12 <= Minimum <= Maximum <= 1e12; step is positive and at most 2e12. False values and unknown fields are refused before allocating controls. Labels accept at most 512 valid UTF-8 bytes without NUL. Options and callback selection are captured at construction, so later table edits do not replace component behavior.
SetValue accepts an in-range finite number. Commit parses the current text with Luau tonumber, clamps a finite number to the bounds and normalizes its display. Invalid/nonfinite text restores the current value and returns false; successful admission returns true. No locale-specific numeric parser is supplied. Equal values normalize text without another OnChanged call. Step buttons clamp at the bounds and are disabled there. Commit and step actions leave active IME preedit alone. An explicit application SetValue can replace the text during composition.
Rendering and callbacks tolerate reentrant value changes or disposal. A newer value wins; retired controls receive no later component callback. OnChanged failure follows the existing State delivery contract with a fixed error. Dispose is idempotent, disconnects owned connections and destroys all four owned controls. Reparenting a part does not transfer its ownership. Destroying an ancestor or any component part retires the controller too. Failed construction cleans up admitted controls and reports ConstructionFailed without the original exception text. GetValue retains the last scalar after retirement; setters and Commit refuse it. All calls belong on LUI’s scheduler thread. The helper creates no competing scheduler or native lifetime model. Callbacks run inline in the current scheduler task. Keep them brief or use the application’s existing task/service cancellation. Dispose does not cancel a callback that already entered or work started by application code. The module Version is 0.1.0.
Scope and State are private cleanup/delivery support files. Keep them with NumericInput, but use NumericInput as the public component API.
Exported type declarations — advanced reference
These types describe returned models/controllers and their options. They are not additional classes to create.
Options
Section titled “Options”export type Options = { Value: number?, Minimum: number?, Maximum: number?, Step: number?, Label: string?, OnChanged: ((number) -> ())?,}Controller
Section titled “Controller”export type Controller = { read View: Frame, read Input: TextBox, read Decrease: TextButton, read Increase: TextButton, GetValue: (Self: Controller) -> number, SetValue: (Self: Controller, Next: number) -> (), Commit: (Self: Controller) -> boolean, Dispose: (Self: Controller) -> (),}Deeper implementation reading
Section titled “Deeper implementation reading”The library source is useful when extending the framework or understanding cleanup. Private support modules such as Scope/State are implementation details, not additional supported app APIs.