Skip to content

Commit fb59ce1

Browse files
bettter keyboard support
1 parent 7fff8ad commit fb59ce1

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustpos-common"
3-
version = "1.3.1"
3+
version = "1.3.2"
44
edition = "2024"
55

66
[dependencies]

frontend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustpos"
3-
version = "1.3.1"
3+
version = "1.3.2"
44
edition = "2024"
55

66
[lib]

frontend/src/pages/keyboard.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,39 @@ use leptos::prelude::*;
22

33
use crate::i18n::I18n;
44

5+
// When the keyboard is shown it may render below the visible area on tall forms
6+
// (e.g. the item editor). Scroll it into view so it is always reachable.
7+
#[cfg(target_arch = "wasm32")]
8+
fn scroll_osk_into_view() {
9+
use wasm_bindgen::prelude::*;
10+
let cb = Closure::wrap(Box::new(move || {
11+
if let Some(el) = web_sys::window()
12+
.and_then(|w| w.document())
13+
.and_then(|d| d.query_selector(".osk").ok())
14+
.flatten()
15+
{
16+
// align to bottom of viewport so the field being edited stays visible
17+
el.scroll_into_view_with_bool(false);
18+
}
19+
}) as Box<dyn Fn()>);
20+
let _ = web_sys::window()
21+
.unwrap()
22+
.request_animation_frame(cb.as_ref().unchecked_ref());
23+
cb.forget();
24+
}
25+
26+
#[cfg(not(target_arch = "wasm32"))]
27+
fn scroll_osk_into_view() {}
28+
529
#[component]
630
pub fn OnScreenKeyboard(
731
on_key: impl Fn(String) + Copy + Send + 'static,
832
shift: ReadSignal<bool>,
933
i18n: RwSignal<I18n>,
1034
) -> impl IntoView {
35+
// Runs once when the keyboard mounts (i.e. when it becomes visible)
36+
Effect::new(move |_| { scroll_osk_into_view(); });
37+
1138
let rows_lower = vec![
1239
vec!["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
1340
vec!["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],

frontend/style/main.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,18 @@ button:focus-visible {
24792479

24802480
.admin-input-row input {
24812481
flex: 1;
2482+
min-width: 0;
2483+
}
2484+
2485+
/* Inside the multi-column grid forms (items, categories) the columns are too
2486+
narrow to fit the keyboard toggle beside the input, so stack it underneath. */
2487+
.form-grid .admin-input-row {
2488+
flex-direction: column;
2489+
align-items: stretch;
2490+
}
2491+
2492+
.form-grid .admin-input-row input {
2493+
flex: 0 0 auto;
24822494
}
24832495

24842496
.admin-role-buttons {

0 commit comments

Comments
 (0)