Keypad for Slint
KitKeypad · Slint Kit 0.9.0
Numeric keypad for a code, a PIN or a quantity: digits 1 to 9, then delete, 0 and confirm.
The still preview and demo follow the documentation theme. You can change it before or during the demo.

This preview runs the actual Slint components and their Rust code compiled to WebAssembly. Slint draws the interface in the browser; the downloadable project compiles the same example into a native application for your platform.
Try the component
Download the complete project, extract it and run cargo run --locked in its folder. To add this component to an application, follow Project setup, then copy the two files below.
The kit supplies the component's behavior and styles; Rust callbacks connect its typed values to your application.
Enter 2468 and choose Unlock to see Locker unlocked. Try a different four-digit code for Wrong code, try again; either result clears the draft. Delete or Backspace removes the last digit. Rust stores at most four typed decimal digits, ignores extra digits and rejects incomplete confirmation. The example code is public demonstration data, not an authentication service.
ui/app.slint
// SPDX-License-Identifier: GPL-3.0-or-later
import { InterFont } from "@kit-fonts/inter.slint";
export { HtmlInputKind, NumberInputFormat, KitInputConstraints, KitValidationResult, KitValidityState } from "@kit";
import { KitKeypad, KitCodeIndicator, KitTheme, KitThemeContext, KitMetrics, TypographyRole } from "@kit";
export component App inherits Window {
default-font-family: InterFont.family;
default-font-size: KitMetrics.font-size(root.theme, TypographyRole.body);
title: "Keypad";
preferred-width: 440px; preferred-height: 580px;
max-width: 100000px; max-height: 100000px;
in-out property <KitTheme> theme: KitThemeContext.current;
background: root.theme.canvas;
// Rust owns the code; the window only learns how many digits it holds.
in property <int> entered;
in property <int> code-length;
in property <bool> can-confirm;
in property <string> status;
callback digit(int);
callback delete-requested();
callback confirm();
VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
Text { text: "Locker code"; color: root.theme.text-primary; font-size: 22px * root.theme.text-scale; font-weight: 600; }
Text { text: "Try the example code 2468, or another four-digit code."; color: root.theme.text-secondary; wrap: word-wrap; }
KitCodeIndicator { theme: root.theme; length: root.code-length; filled: root.entered; label: root.entered + " of " + root.code-length + " digits entered"; }
HorizontalLayout { alignment: center;
keypad := KitKeypad { theme: root.theme; label: "Locker code"; confirm-label: "Unlock"; can-confirm: root.can-confirm;
digit(value) => { root.digit(value); }
delete-requested => { root.delete-requested(); }
confirm => { root.confirm(); }
}
}
result := Text { text: root.status; color: root.theme.text-secondary; wrap: word-wrap; }
}
}
src/main.rs
// SPDX-License-Identifier: GPL-3.0-or-later
use slint::ComponentHandle;
use slint_kit::{action, event};
use std::{cell::RefCell, rc::Rc};
mod ui { slint::include_modules!(); }
#[derive(Clone, Copy, PartialEq, Eq)] struct Digit(u8);
fn show(app: &ui::App, code: &[Digit], status: &str) { app.set_entered(i32::try_from(code.len()).expect("four digits")); app.set_can_confirm(code.len() == 4); app.set_status(status.into()); }
fn main() -> Result<(), slint::PlatformError> {
let app = ui::App::new()?; slint_kit::install(&app); app.set_code_length(4);
let code: Rc<RefCell<Vec<Digit>>> = Rc::default(); let entered = code.clone();
app.on_digit(event(&app, move |app, value| { let mut code = entered.borrow_mut(); if let Ok(digit) = u8::try_from(value) && digit <= 9 && code.len() < 4 { code.push(Digit(digit)); } show(&app, &code, ""); }));
let entered = code.clone(); app.on_delete_requested(action(&app, move |app| { let mut code = entered.borrow_mut(); code.pop(); show(&app, &code, ""); }));
app.on_confirm(action(&app, move |app| { let mut code = code.borrow_mut(); if code.len() != 4 { return; } let status = if code.as_slice() == [Digit(2), Digit(4), Digit(6), Digit(8)] { "Locker unlocked" } else { "Wrong code, try again" }; code.clear(); show(&app, &code, status); }));
app.run()
}
Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs
Supply label, confirm-label and can-confirm, and handle digit(int), delete-requested() (remove the last digit) and confirm() in the owning model, which keeps the entered code. Localize delete-label, confirm-label and, when needed, the ten digit-labels in keypad order. delete-glyph (by default the theme’s delete icon), confirm-glyph and confirm-intent customize the two action keys. Show progress with KitCodeIndicator. Use activation-started() for immediate press feedback; digits, deletion and confirmation still commit through their existing callbacks. Compose KitCodeIndicator explicitly: update filled and its localized label from admitted digit/delete callbacks, and bind its validation to host-owned ValidationPresentation. Include error/success feedback in that label when needed; do not expose the code. Set digits-enabled: false once the code is full and can-delete: false while it is empty; both disable the matching keys and typed input. show-confirm: false hides confirm and frees the bottom-right slot for one extra key (extra-label, extra-glyph, extra-enabled, extra()), for example a decimal separator or a cancel key; the host decides what it enters. handle-escape: true makes Escape emit cancel().
The keypad emits intentions only and never holds the digits. 0 to 9 and Backspace reach the same callbacks while a key or the keypad has focus. Return confirms on the keypad; Return and Space first activate a key that shows keyboard focus, as on any button. A key pressed with the pointer hands focus back to the keypad without a ring, so Return after tapped digits confirms. take-focus() focuses the keypad itself. Confirm stays disabled while can-confirm is false, and a held Return confirms once. A read-only or disabled keypad emits nothing. Each key keeps a minimum twelve-spacing-unit touch target and grows vertically with enlarged text; the group exposes label and each key its own label. Key width can shrink independently of height, so a 320px keypad remains usable at 200% text with the shipped themes. Pointer-down and Space-down emit activation-started before commit; cancellation can therefore produce feedback without a digit. Typed digits, Backspace, Return and accessible actions emit it immediately before their action. Disabled, read-only and unavailable confirm keys emit nothing. The keypad does not update or announce an indicator automatically. activation-started is press feedback, not evidence that a digit was accepted; drive progress from digit/delete callbacks and validation from the host result. The starter does not request programmatic focus on load. Tab still reaches native keys with their own focus indicator; explicit take-focus() retains the documented keypad-scope behavior. Delete behaves like Backspace. With show-confirm: false, Return no longer confirms, and an empty extra-label leaves the slot empty. Escape emits cancel() only while handle-escape is true and the keypad is editable; otherwise it reaches the surroundings. Hold-to-clear, scrambled digit order, secondary key labels and arrow-key movement between keys are not provided. Delete behaves like Backspace. With show-confirm: false, Return no longer confirms, and an empty extra-label leaves the slot empty. Escape emits cancel() only while handle-escape is true and the keypad is editable; otherwise it reaches the surroundings. The twelve keys are one tab stop: Tab reaches the key that last had focus (the first available key at first), and the next Tab leaves the keypad. The arrow keys move focus to the key drawn on that side without wrapping and skip unavailable keys; Home and End go to the first and last available key of the row. The key layout is never mirrored, as on any numeric pad, so Left and Right follow the drawn position in right-to-left text too. Arrow keys with Shift, Control, Alt or Meta are left to the surroundings. Hold-to-clear, scrambled digit order and secondary key labels are not provided.
Choose between built-in options and custom composition
Shared options
label— built-in property; custom composition example
Visual composition
The file below describes the captured scene. For controller-driven components, it shows the displayed state without supplying the Rust wiring. Create a project.
Show the screenshot source

// SPDX-License-Identifier: GPL-3.0-or-later
import { InterFont } from "@kit-fonts/inter.slint";
import { KitKeypad, KitCodeIndicator, ValidationPresentation, ControlSize, KitTheme, KitThemes, KitMetrics, TypographyRole } from "@kit";
export component Example inherits Window {
default-font-family: InterFont.family;
default-font-size: KitMetrics.font-size(root.theme, TypographyRole.body);
title: "Keypad";
preferred-width: 440px; preferred-height: 560px;
max-width: 100000px; max-height: 100000px;
in-out property <KitTheme> theme: KitThemes.light;
background: root.theme.canvas;
// The example counts digits only; a real host keeps the code in Rust.
in-out property <int> entered;
// The host supplies validation and localized feedback; the label never contains the code.
in-out property <ValidationPresentation> validation: ValidationPresentation.pristine;
in-out property <string> feedback;
in-out property <string> status;
VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
Text { text: "Locker code"; color: root.theme.text-primary; font-size: 22px * root.theme.text-scale; font-weight: 600; }
Text { text: "Enter the four-digit code printed on your receipt."; color: root.theme.text-secondary; wrap: word-wrap; }
KitCodeIndicator { theme: root.theme; validation: root.validation; control-size: ControlSize.medium; length: 4; filled: root.entered; label: root.entered + " of 4 digits entered" + (root.feedback == "" ? "" : ". " + root.feedback); }
HorizontalLayout { alignment: center;
KitKeypad { theme: root.theme; label: "Locker code"; confirm-label: "Open locker"; can-confirm: root.entered == 4;
activation-started => { root.status = "Key pressed"; }
digit(value) => { root.entered = min(4, root.entered + 1); root.validation = ValidationPresentation.pristine; root.feedback = ""; }
delete-requested => { root.entered = max(0, root.entered - 1); root.validation = ValidationPresentation.pristine; root.feedback = ""; }
confirm => { root.status = "Code submitted for checking"; root.entered = 0; root.validation = ValidationPresentation.checking; root.feedback = root.status; }
}
}
if root.status != "": Text { text: root.status; color: root.theme.text-secondary; wrap: word-wrap; }
}
}
Public API
Inherits Rectangle.
Properties
The "Default" column repeats the initializer declared in the source; "—" is the zero value of the type, and a composite expression points to the source.
| Name | Type | Direction | Default |
|---|---|---|---|
modal-layer |
int |
in |
— |
theme |
KitTheme |
in |
KitThemeContext.current |
control-size |
ControlSize |
in |
ControlSize.comfortable |
access |
FieldAccess |
in |
FieldAccess.editable |
label |
string |
in |
— |
digit-labels |
[string] |
in |
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] |
delete-label |
string |
in |
"Delete" |
delete-glyph |
IconGlyph |
in |
root.theme.icons.delete |
confirm-label |
string |
in |
"Confirm" |
confirm-glyph |
IconGlyph |
in |
root.theme.icons.check |
confirm-intent |
ButtonIntent |
in |
ButtonIntent.primary |
key-height |
length |
in |
root.theme.spacing.unit * 12 |
digit-role |
TypographyRole |
in |
TypographyRole.title |
can-confirm |
bool |
in |
— |
digits-enabled |
bool |
in |
true |
can-delete |
bool |
in |
true |
show-confirm |
bool |
in |
true |
extra-label |
string |
in |
— |
extra-glyph |
IconGlyph |
in |
— |
extra-enabled |
bool |
in |
true |
handle-escape |
bool |
in |
false |
Property details
Effect, default, states and constraints of the central properties, with a snippet that uses public mechanisms. Inherited properties carry the explanation of the component that declares them. The complete typed example and the Forms guide wire these properties end to end.
modal-layer
The modal layer this component belongs to; 0 is the window. While a KitDialogSurface or KitDrawer with a positive modal-layer is open and topmost, the component is inert: its keys and keyboard scope take no focus and ignore pointer and keys. Give a component placed inside a modal that modal’s layer number.
- Default
0(window).
KitKeypad {
modal-layer: 1;
}
key-height
The least height of a key. A key still grows with its control size and with the digit it shows, so the grid never clips a digit.
- Default
theme.spacing.unit * 12(48px): a square touch target.
KitKeypad {
key-height: 64px;
}
digit-role
The typography role of the ten digit labels, read through KitMetrics.font-size, so the digits follow the theme's text scale. The delete and confirm keys keep their glyphs.
- Default
TypographyRole.title.
KitKeypad {
digit-role: TypographyRole.display;
}
Types and variants
| Type | Declaration |
|---|---|
enum ButtonIntent |
primary, secondary, outline, quiet, destructive, success, warning, information, link |
enum ControlSize |
compact, medium, comfortable |
enum FieldAccess |
editable, read-only, disabled |
enum TypographyRole |
caption, control, body, subtitle, title, display |
Callbacks
activation-started()digit(int)delete-requested()confirm()extra()cancel()
Functions
take-focus()