Question
I'm developing a login screen for Tizen TV and need to implement the following behavior:
- Input box switching when pressing up/down keys
- Highlighting the focused input box
- Launching the keypad when pressing OK key
I'm looking for code samples or implementation examples that achieve this functionality, similar to the UX described in the Samsung Tizen UX Guide (https://www.samsungdforum.com/TizenUxGuide/05/05_text_input.html#ux-09).
Answer
Problem Understanding
The user wants to create a TV login screen with consecutive input fields that:
- Can be navigated using up/down keys
- Show visual focus indication
- Trigger the on-screen keyboard when pressing OK on a focused input field
Solution Methods
-
Input Navigation:
- Use JavaScript event listeners for keydown events
- Implement focus switching between input fields based on arrow key presses
-
Focus Styling:
- Apply CSS styles to visually indicate the focused input field
- Use :focus pseudo-class or custom classes for better visual feedback
-
Keyboard Handling:
- Note that programmatic keyboard triggering is limited on Tizen TV
- The system typically handles keyboard display automatically when an input receives focus
Code Examples
// Sample implementation for consecutive input navigation
document.addEventListener('keydown', function(e) {
const activeElement = document.activeElement;
const inputs = document.querySelectorAll('input[type="text"]');
const currentIndex = Array.from(inputs).indexOf(activeElement);
if (e.keyCode === 38) { // Up arrow
e.preventDefault();
const prevIndex = (currentIndex - 1 + inputs.length) % inputs.length;
inputs[prevIndex].focus();
} else if (e.keyCode === 40) { // Down arrow
e.preventDefault();
const nextIndex = (currentIndex + 1) % inputs.length;
inputs[nextIndex].focus();
} else if (e.keyCode === 13) { // OK/Enter key
// Focus handling for keyboard display
activeElement.focus();
}
});
// CSS for focus styling
input:focus {
border: 2px solid #00a0e6;
background-color: #f0f8ff;
}
Additional Tips
- For a complete working example, refer to this JSFiddle: https://jsfiddle.net/d1m9sxr7/1/
- Be aware that some TV models might have different behaviors for keyboard handling
- Test your implementation on actual TV hardware for best results
- Consider accessibility requirements when implementing focus indicators