Skip to content

fix(hiddenTextarea): use correct tabindex attribute to prevent keyboard focus#81

Open
tyreer wants to merge 1 commit intoreact-component:masterfrom
tyreer:fix/hidden-textarea-tabindex
Open

fix(hiddenTextarea): use correct tabindex attribute to prevent keyboard focus#81
tyreer wants to merge 1 commit intoreact-component:masterfrom
tyreer:fix/hidden-textarea-tabindex

Conversation

@tyreer
Copy link

@tyreer tyreer commented Feb 4, 2026

Summary

Fixes the hidden textarea keyboard focus issue by using the correct tabindex attribute instead of the invalid tab-index (with hyphen).

Problem

The hidden textarea used for auto-size height calculation is keyboard-focusable because tab-index is not a valid HTML attribute. Browsers ignore invalid attributes, leaving the element in the tab order.

Changes

  • Fix: Changed setAttribute('tab-index', '-1')setAttribute('tabindex', '-1') in src/calculateNodeHeight.tsx
  • Tests: Added accessibility tests verifying hidden textarea has correct tabindex="-1" attribute

Related Issue

Fixes #80

Testing

  • All 55 existing tests pass

  • Added 2 new accessibility tests:

    • should have tabindex="-1" to prevent keyboard focus
    • should have aria-hidden="true" for screen readers
  • Lint passes (pre-existing warnings only)

Additional Context

This bug was introduced in v0.2.0 (fee4e45, June 2020) and has been present for ~5.5 years.

This PR complements #59 which added the name="hiddenTextarea" attribute for form validation.

Summary by CodeRabbit

发布说明

  • Bug 修复

    • 修正了隐藏测量组件的DOM属性配置,确保正确的可访问性设置。
  • 测试

    • 添加了可访问性测试,验证隐藏组件的标签索引和屏幕阅读器设置。

@gemini-code-assist
Copy link

Summary of Changes

Hello @tyreer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a long-standing accessibility bug concerning the hidden textarea used for auto-sizing. By correcting an invalid HTML attribute (tab-index to tabindex), the textarea is now properly excluded from keyboard navigation, improving the user experience for keyboard users. The change is accompanied by new dedicated accessibility tests to ensure its correctness and prevent future regressions.

Highlights

  • Accessibility Fix: Corrected an accessibility issue where a hidden textarea, used for auto-sizing, was unintentionally keyboard-focusable due to the use of an invalid tab-index attribute.
  • Attribute Correction: Replaced the incorrect tab-index attribute with the valid tabindex attribute, setting its value to -1 to remove the element from the tab order.
  • New Accessibility Tests: Introduced new tests to verify that the hidden textarea correctly has tabindex="-1" to prevent keyboard focus and aria-hidden="true" for screen reader exclusion.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/calculateNodeHeight.tsx
    • Replaced hiddenTextarea.setAttribute('tab-index', '-1') with hiddenTextarea.setAttribute('tabindex', '-1') to use the correct HTML attribute for keyboard focus control.
  • tests/index.spec.tsx
    • Added a new test suite, Hidden Textarea Accessibility, which includes two new tests:
    • One verifies that the hidden textarea has tabindex="-1" and does not have the invalid tab-index attribute.
    • Another verifies that the hidden textarea has aria-hidden="true".
    • Made a minor formatting adjustment to a jest.spyOn call.
Activity
  • The pull request was authored by tyreer.
  • It addresses a bug that has been present in the codebase for approximately 5.5 years, since June 2020.
  • The changes complement a previous pull request (fix(hiddenTextarea): A form field element should have an id or name attribute #59) which added the name="hiddenTextarea" attribute.
  • The author has confirmed that all existing tests pass and has added two new accessibility-focused tests.
  • Linting checks passed, with only pre-existing warnings noted.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

概览

修复了隐藏textarea中的HTML属性错误,将无效的tab-index(带连字符)更正为有效的tabindex(无连字符),防止隐藏textarea被键盘导航聚焦。同时添加了相关的无障碍测试验证。

变更

群组 / 文件 摘要
属性修复
src/calculateNodeHeight.tsx
纠正DOM属性名称:setAttribute('tab-index', '-1') 更改为 setAttribute('tabindex', '-1'),符合HTML规范。
无障碍测试
tests/index.spec.tsx
添加"隐藏Textarea无障碍性"测试块,验证隐藏textarea具有有效的tabindex="-1"属性且包含aria-hidden="true"

估计代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟

诗歌

🐰 一个字符的修复,焕发新生,
隐藏的框框,不再捣乱,
键盘侠们,轻轻滑过,
无障碍之光,照亮前路,✨
小小改动,大大关怀!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要变更——修复隐藏文本框的 tabindex 属性,防止键盘焦点,与代码变更完全一致。
Linked Issues check ✅ Passed 代码变更完全满足 #80 的所有要求:将 'tab-index' 改为 'tabindex',添加了验证 tabindex="-1" 和 aria-hidden="true" 的可访问性测试。
Out of Scope Changes check ✅ Passed 所有变更都在范围内,仅涉及修复隐藏文本框的 tabindex 属性和相关的可访问性测试,没有无关的修改。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an accessibility issue by fixing a typo in the tabindex attribute on a hidden textarea, preventing it from being keyboard-focusable. The change is simple and effective. The inclusion of new accessibility tests is a great addition, ensuring the fix is verified and preventing future regressions. I've added one suggestion to refactor the new tests for better conciseness and maintainability.

Comment on lines +426 to +454
describe('Hidden Textarea Accessibility', () => {
it('should have tabindex="-1" to prevent keyboard focus', () => {
// Create a textarea to trigger hidden textarea creation
const wrapper = document.createElement('textarea');
calculateAutoSizeStyle(wrapper);

// Find the hidden textarea used for height measurement
const hiddenTextarea = document.querySelector(
'textarea[name="hiddenTextarea"]',
);

expect(hiddenTextarea).toBeInTheDocument();
// Verify correct tabindex attribute (without hyphen)
expect(hiddenTextarea).toHaveAttribute('tabindex', '-1');
// Ensure the invalid "tab-index" attribute is NOT present
expect(hiddenTextarea).not.toHaveAttribute('tab-index');
});

it('should have aria-hidden="true" for screen readers', () => {
const wrapper = document.createElement('textarea');
calculateAutoSizeStyle(wrapper);

const hiddenTextarea = document.querySelector(
'textarea[name="hiddenTextarea"]',
);

expect(hiddenTextarea).toHaveAttribute('aria-hidden', 'true');
});
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's great that you've added tests for accessibility. To make the tests more concise and avoid duplicating the setup logic, consider combining these two related checks into a single test case. This would test the overall accessibility state of the hidden textarea in one place.

describe('Hidden Textarea Accessibility', () => {
  it('should have correct accessibility attributes', () => {
    // Create a textarea to trigger hidden textarea creation
    const wrapper = document.createElement('textarea');
    calculateAutoSizeStyle(wrapper);

    // Find the hidden textarea used for height measurement
    const hiddenTextarea = document.querySelector(
      'textarea[name="hiddenTextarea"]',
    );

    expect(hiddenTextarea).toBeInTheDocument();

    // Should have tabindex="-1" to prevent keyboard focus
    expect(hiddenTextarea).toHaveAttribute('tabindex', '-1');
    expect(hiddenTextarea).not.toHaveAttribute('tab-index');

    // Should have aria-hidden="true" for screen readers
    expect(hiddenTextarea).toHaveAttribute('aria-hidden', 'true');
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Hidden textarea is keyboard-focusable due to "tab-index" typo (should be "tabindex")

1 participant