Exclude collapsed expander content from browser find-in-page (Cmd+F)#13818
Exclude collapsed expander content from browser find-in-page (Cmd+F)#13818lukasmasuch merged 5 commits intodevelopfrom
Conversation
Add the inert attribute to the expander content panel when collapsed, which tells browsers to exclude it from find-in-page searches. This prevents users from being confused by search matches on hidden text in collapsed expanders. Includes unit tests to verify the inert attribute is correctly applied and toggled when expanding/collapsing. Co-Authored-By: Claude (claude-haiku-4-5) <[email protected]>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
Co-Authored-By: Claude (claude-opus-4-5) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds the HTML inert attribute to expander content panels when collapsed, preventing browsers from including hidden text in find-in-page (Cmd+F) searches. This improves the user experience by ensuring search matches only highlight visible content.
Changes:
- Added
inertattribute toStyledDetailsPanelwhen the expander is collapsed - Created comprehensive unit tests to verify the attribute is correctly applied/removed based on expanded state
- Documented the technical approach and considerations
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
frontend/lib/src/components/elements/Expander/styled-components.ts |
Added StyledDetailsPanelProps interface with inert property definition |
frontend/lib/src/components/elements/Expander/Expander.tsx |
Applied inert attribute conditionally based on expanded state |
frontend/lib/src/components/elements/Expander/Expander.test.tsx |
Added three tests verifying inert attribute behavior (collapsed, expanded, toggle) |
expander-search-plan.md |
Planning documentation explaining the implementation approach and alternatives |
Co-Authored-By: Claude (claude-opus-4-5) <[email protected]>
Co-Authored-By: Claude (claude-opus-4-5) <[email protected]>
SummaryThis PR adds the Files Changed:
Code QualityThe implementation is clean and follows established patterns in the codebase: Positives:
No issues identified with the code structure or patterns. Test CoverageThe unit tests are well-written and follow RTL best practices:
Strengths:
Minor observation: There is no test for the reverse toggle (expanded → collapsed), though the existing tests cover the core behavior adequately. The E2E tests already cover expand/collapse interactions, and browser find-in-page behavior cannot be tested in Playwright, so the current unit test coverage is reasonable. Backwards CompatibilityNo breaking changes. This is a purely frontend UX enhancement:
Behavior change (expected): Users will notice that collapsed expander content no longer appears in browser find-in-page results. This is the intended improvement. Accessibility note: The Security & RiskNo security concerns. This is a presentational change that uses a standard HTML attribute. Low regression risk:
RecommendationsNo blocking issues. The PR is ready for merge. Optional enhancement (non-blocking):
it("adds inert attribute when collapsing", async () => {
const user = userEvent.setup()
const props = getProps({ expanded: true })
render(
<Expander {...props}>
<div>test</div>
</Expander>
)
const panel = screen.getByTestId("stExpanderDetails")
expect(panel).not.toHaveAttribute("inert")
await user.click(screen.getByText("hi"))
expect(panel).toHaveAttribute("inert")
})However, this is not required as the current tests adequately validate the feature. VerdictAPPROVED: Clean implementation of a useful UX improvement using semantic HTML. Tests are well-written and follow best practices. No backwards compatibility or security concerns. This is an automated AI review using |
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0600%
🎉 Great job on improving test coverage! |
- Add test for expanded → collapsed transition (adds inert) - Add comment explaining why StyledDetailsPanelProps is needed Co-Authored-By: Claude (claude-opus-4-5) <[email protected]>
|
I agree with this approach here, but some of the work I did for dynamic expanders may make it more viable to not render the content when the expander is closed in the future. I had to make changes to the animation in order to support the content being sent after the expander is opened and the script re-runs. I could test that as a follow up, if we think there may be other benefits like having a cleaner DOM. |
It's definitely something we can explore, but we will need a closer evaluation since we had a couple of issues with that in the past. E.g. when not rendering content of |
Describe your changes
Add the
inertattribute to expander content panels when collapsed, preventing browsers from including hidden text in find-in-page (Cmd+F) searches. This solves the issue where users see search matches on collapsed content they can't see.Testing Plan
inertattribute is correctly applied when collapsed and removed when expanded, plus toggling behaviorContribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.