refactor: apply code quality suggestions from task-6-mobile-fab review
Three suggestions from the code review applied:
1. Extract _createSessionInput() factory to eliminate five-line
duplication between showNewSessionInput and showFabSessionInput.
Both functions now call the shared factory. Updated 4 existing
tests to check _createSessionInput's body; added 7 new tests
covering factory behavior and factory usage in each consumer.
2. Fix .new-session-fab:focus-visible outline color from var(--accent)
to var(--bg) — the FAB background is already var(--accent), so
using the same color for the outline created zero contrast.
Added 1 new test to guard this going forward.
3. Add early-return guard in showFabSessionInput against duplicate
overlays: if (document.querySelector('.fab-input-overlay')) return;
Prevents a second overlay being created if called programmatically
while one is already open. Added 1 new test.
532 tests pass (9 new tests added, 523 unchanged).
This commit is contained in:
+15
-7
@@ -1292,13 +1292,24 @@ function updateSessionPill(sessions) {
|
||||
* On blur: delayed cleanup (150ms) to allow click handlers.
|
||||
* @param {HTMLElement} btn - The button element to replace temporarily.
|
||||
*/
|
||||
function showNewSessionInput(btn) {
|
||||
/**
|
||||
* Create a new session name input element with shared base configuration.
|
||||
* Used by both showNewSessionInput (inline) and showFabSessionInput (overlay)
|
||||
* to avoid duplicating the five setup properties.
|
||||
* @returns {HTMLInputElement}
|
||||
*/
|
||||
function _createSessionInput() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
input.className = 'new-session-input';
|
||||
input.placeholder = 'Session name\u2026';
|
||||
input.autocomplete = 'off';
|
||||
input.spellcheck = false;
|
||||
return input;
|
||||
}
|
||||
|
||||
function showNewSessionInput(btn) {
|
||||
const input = _createSessionInput();
|
||||
|
||||
function cleanup() {
|
||||
if (input.parentNode) input.parentNode.removeChild(input);
|
||||
@@ -1331,17 +1342,14 @@ function showNewSessionInput(btn) {
|
||||
* visible on mobile regardless of body/view overflow:hidden constraints.
|
||||
*/
|
||||
function showFabSessionInput() {
|
||||
if (document.querySelector('.fab-input-overlay')) return;
|
||||
|
||||
const fab = $('new-session-fab');
|
||||
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'fab-input-overlay';
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
input.className = 'new-session-input';
|
||||
input.placeholder = 'Session name\u2026';
|
||||
input.autocomplete = 'off';
|
||||
input.spellcheck = false;
|
||||
const input = _createSessionInput();
|
||||
|
||||
overlay.appendChild(input);
|
||||
|
||||
|
||||
@@ -1234,7 +1234,7 @@ body {
|
||||
}
|
||||
|
||||
.new-session-fab:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline: 2px solid var(--bg);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user