refactor: extract shared base for year/month/month-year dropdowns - #92
Open
balajis-qb wants to merge 1 commit into
Open
balajis-qb wants to merge 1 commit into
balajis-qb wants to merge 1 commit into
Conversation
month_dropdown.tsx, year_dropdown.tsx, and month_year_dropdown.tsx were ~90% duplicated: same dropdownVisible state shape, same read-view/select- mode/scroll-mode/toggle skeleton, differing only in what options they render. That divergence had already caused a real bug (Hacker0x01#6311): month_year_dropdown's read view was a plain <div onClick>, unlike the other two which used <button type="button">, so it was unreachable via Tab and didn't respond to Enter/Space. Add dropdown_common.tsx (DropdownReadView, dropdownContainerClassName, renderScrollModeChildren) and use it in all three components. Unifying the read view onto a real <button> fixes Hacker0x01#6311 as a structural side effect of removing the duplication, not just a targeted patch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Structural cleanup — no linked issue.
month_dropdown.tsx,year_dropdown.tsx, andmonth_year_dropdown.tsxwere nearly identical and had already drifted apart in a way that broke accessibility for one of them.Problem
month_dropdown.tsx,year_dropdown.tsx, andmonth_year_dropdown.tsxwere ~90% duplicated: samedropdownVisiblestate shape, same read-view / select-mode / scroll-mode / toggle skeleton — only the rendered options differed.month_year_dropdown.tsx's read view was a plain<div onClick>instead of a<button type="button">like the other two, so it wasn't reachable via Tab and didn't respond to Enter/Space (tracked upstream as issue showMonthYearDropdown read view not reachable via Tab / keyboard Hacker0x01/react-datepicker#6311).DropdownReadViewbutton, the BEM container class builder, and the scroll-mode array assembly) intosrc/dropdown_common.tsx, and have all three components use it. Unifying onto one read-view implementation fixes the div-vs-button bug as a structural side effect of removing the duplication, not as a separate targeted patch.Changes
src/dropdown_common.tsx:DropdownReadView(shared toggle button),dropdownContainerClassName,renderScrollModeChildren.src/year_dropdown.tsx,src/month_dropdown.tsx,src/month_year_dropdown.tsx: replace hand-copied read-view/container-class/scroll-mode JSX with the shared helpers.src/test/dropdown_common.test.tsx(new): direct test coverage for the extracted module.src/test/month_year_dropdown_test.test.tsx: add a regression test asserting the read view renders as a real<button type="button">.Screenshots
Not applicable — This is a structural refactor with no visual change. The same CSS classes and markup shape are reused; the only element-tag change (
div→button) is covered by tests rather than being visually apparent.Contribution checklist