Keep the description selected after Tab in every browser

Browsers like Safari and Firefox place the cursor in a textarea after its focus event, undoing the
selection, so Tab from the product into the description left the cursor at the start. The box is now
selected on focus, once more after the browser has placed its cursor, and again on the Tab key's release,
each only while nothing has been typed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 13:11:01 -04:00
1 parent d91e80199e
commit 846fcad292
1 file changed
+14 -2
+14 -2
View File
@@ -339,8 +339,20 @@ $(function () {
$(document).on('mousedown touchstart', function () { tabbedAt = 0; }); $(document).on('mousedown touchstart', function () { tabbedAt = 0; });
$tbody.on('focus', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function () { $tbody.on('focus', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function () {
if (Date.now() - tabbedAt > 500) return; if (Date.now() - tabbedAt > 500) return;
// Right away, so the first key typed already replaces the text // Right away, so the first key typed already replaces the text; and again once the browser has placed
this.select(); // its cursor (a textarea, the description, puts it back at the start), unless typing has begun
var box = this, before = box.value;
$(box).data('qboTabbedValue', before);
box.select();
setTimeout(function () { if (document.activeElement === box && box.value === before) box.select(); }, 0);
});
// Some browsers (Safari, Firefox) place the cursor after that; the Tab key's release arrives here once they
// have, so select again if nothing was typed yet
$tbody.on('keyup', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function (event) {
if (event.key !== 'Tab') return;
var tabbed = $(this).data('qboTabbedValue');
$(this).removeData('qboTabbedValue');
if (tabbed !== undefined && this.value === tabbed) this.select();
}); });
// ---- line events ---- // ---- line events ----