From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 8406A1FF0B7 for ; Fri, 16 Oct 2026 11:03:00 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 26326214D8; Fri, 16 Oct 2026 11:03:00 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit 5/5] widget: data table: header: skip hidden cells in keyboard navigation Date: Fri, 16 Oct 2026 11:01:14 +0200 Message-ID: <20261016090256.1170172-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261016090256.1170172-1-d.csapak@proxmox.com> References: <20261016090256.1170172-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.358 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: XR6ZPDIQXLCZE4T2YJ443HZM6DKTMXTW X-Message-ID-Hash: XR6ZPDIQXLCZE4T2YJ443HZM6DKTMXTW X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When moving the header cursor with the arrow keys, we go over all header cells, including the hidden ones. Since those are not rendered, the focus does not move, so the user has to press the arrow key once more for every hidden cell in between. Also, only the cell of the cursor (or the first cell if there is no cursor) gets 'tabindex=0'. When that cell is hidden, no rendered cell is a tab stop and the header can't be reached with the tab key at all. This happens e.g. when hiding the focused column via its own header menu, or when the first header cell is hidden from the start, e.g. a first column with 'hidden(true)'. To reproduce: * focus a column header and hide that column via its header menu * try to tab into the header, it is skipped * focus the column left of the hidden one and press the right arrow key, the focus does not move Fix this by skipping hidden cells when moving the cursor, and by using the first visible cell as tab stop when the cursor cell is hidden. Signed-off-by: Dominik Csapak --- src/widget/data_table/header_widget.rs | 57 +++++++++++++------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/widget/data_table/header_widget.rs b/src/widget/data_table/header_widget.rs index 2f55e88..0c0ff45 100644 --- a/src/widget/data_table/header_widget.rs +++ b/src/widget/data_table/header_widget.rs @@ -193,6 +193,21 @@ impl PwtHeaderWidget { span } + fn cell_visible(&self, cell_idx: usize) -> bool { + cell_idx < self.state.cell_count() && !self.state.get_cell_hidden(cell_idx) + } + + // The cell that gets focus when tabbing into the header. Hidden cells are not rendered, so + // fall back to the first visible one. + fn tab_stop(&self) -> Option { + match self.cursor { + Some(cursor) if self.cell_visible(cursor) => Some(cursor), + Some(_) | None => { + (0..self.state.cell_count()).find(|cell_idx| self.cell_visible(*cell_idx)) + } + } + } + fn unique_cell_id(&self, cell_idx: usize) -> String { format!("{}-cell-{}", self.unique_id, cell_idx) } @@ -208,11 +223,7 @@ impl PwtHeaderWidget { ) { let column_idx = cell.start_col; let cell_idx = cell.cell_idx; - let active = self - .cursor - .map(|cursor| cursor == cell_idx) - .unwrap_or(false); - let tabindex = if active || (self.cursor.is_none() && (cell_idx == 0)) { + let tabindex = if self.tab_stop() == Some(cell_idx) { AttrValue::Static("0") } else { AttrValue::Static("-1") @@ -387,11 +398,7 @@ impl PwtHeaderWidget { header_row: &mut Vec, ) -> usize { let cell_idx = group.cell_idx; - let active = self - .cursor - .map(|cursor| cursor == cell_idx) - .unwrap_or(false); - let tabindex = if active || (self.cursor.is_none() && (cell_idx == 0)) { + let tabindex = if self.tab_stop() == Some(cell_idx) { "0" } else { "-1" @@ -593,28 +600,22 @@ impl Component for PwtHeaderWidget { true } Msg::MoveCursor(direction) => { - let last = self.state.cell_count().saturating_sub(1); + let count = self.state.cell_count(); let cursor = match self.cursor { Some(cursor) => cursor, None => return false, }; - self.cursor = Some(match direction { - false => { - if cursor > 0 { - cursor - 1 - } else { - last - } - } - true => { - if (cursor + 1) <= last { - cursor + 1 - } else { - 0 - } - } - }); - self.focus_active_cell(); + // Wrap around at either end and skip hidden cells, as they are not rendered. + let next = (1..count) + .map(|step| match direction { + true => (cursor + step) % count, + false => (cursor + count - step) % count, + }) + .find(|cell_idx| self.cell_visible(*cell_idx)); + if let Some(next) = next { + self.cursor = Some(next); + self.focus_active_cell(); + } true } } -- 2.47.3