Skip to content

Commit

Permalink
Fix batch tally entry auto-focus bug when there are multiple contests (
Browse files Browse the repository at this point in the history
  • Loading branch information
arsalansufi authored Mar 6, 2024
1 parent f09f169 commit 4913d5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ const BatchResultTallySheet: React.FC<IBatchResultTallySheetProps> = ({
aria-labelledby={`${Classes.TAB_PANEL}_${batch.name}_${selectedTabId}`}
role="tabpanel"
>
{contests.map(contest => (
{contests.map((contest, contestIndex) => (
<BatchResultTallySheetTable key={contest.id}>
<thead>
<tr>
Expand All @@ -521,7 +521,7 @@ const BatchResultTallySheet: React.FC<IBatchResultTallySheetProps> = ({
</tr>
</thead>
<tbody>
{contest.choices.map((choice, i) => (
{contest.choices.map((choice, choiceIndex) => (
<tr key={choice.id}>
<td>{choice.name}</td>
<td>
Expand All @@ -540,7 +540,11 @@ const BatchResultTallySheet: React.FC<IBatchResultTallySheetProps> = ({
// since we're auto-focusing after a relevant user action and the input is
// clearly labeled
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={!isSelectedSheetNewAndUnsaved && i === 0}
autoFocus={
!isSelectedSheetNewAndUnsaved &&
contestIndex === 0 &&
choiceIndex === 0
}
className={classnames(
Classes.INPUT,
errors.results?.[choice.id] && Classes.INTENT_DANGER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('Batch comparison data entry', () => {
let row2 = within(rows[3]).getAllByRole('cell')
const choice1VotesInput = within(row1[1]).getByRole('spinbutton')
let choice2VotesInput = within(row2[1]).getByRole('spinbutton')
expect(choice1VotesInput).toHaveFocus()
userEvent.type(choice1VotesInput, '1')
userEvent.clear(choice2VotesInput)

Expand Down Expand Up @@ -299,6 +300,7 @@ describe('Batch comparison data entry', () => {
expect(row2).toHaveLength(2)
let choice1VotesInput = within(row1[1]).getByRole('spinbutton')
let choice2VotesInput = within(row2[1]).getByRole('spinbutton')
expect(choice1VotesInput).toHaveFocus()
expect(choice1VotesInput).toHaveTextContent('')
expect(choice2VotesInput).toHaveTextContent('')

Expand Down Expand Up @@ -479,6 +481,7 @@ describe('Batch comparison data entry', () => {
let table1Row2 = within(table1Rows[3]).getAllByRole('cell')
const choice1VotesInput = within(table1Row1[1]).getByRole('spinbutton')
const choice2VotesInput = within(table1Row2[1]).getByRole('spinbutton')
expect(choice1VotesInput).toHaveFocus()
userEvent.type(choice1VotesInput, '1')
userEvent.type(choice2VotesInput, '2')

Expand Down Expand Up @@ -590,6 +593,7 @@ describe('Batch comparison data entry', () => {
let choice2VotesInput = within(table1Row2[1]).getByRole('spinbutton')
let choice3VotesInput = within(table2Row1[1]).getByRole('spinbutton')
let choice4VotesInput = within(table2Row2[1]).getByRole('spinbutton')
expect(choice1VotesInput).toHaveFocus()
expect(choice1VotesInput).toHaveTextContent('')
expect(choice2VotesInput).toHaveTextContent('')
expect(choice3VotesInput).toHaveTextContent('')
Expand Down

0 comments on commit 4913d5d

Please sign in to comment.