Skip to content

fix(select,multiselect): properly handle defaults and prompts#642

Merged
caarlos0 merged 4 commits intomainfrom
select-accessible
Apr 29, 2025
Merged

fix(select,multiselect): properly handle defaults and prompts#642
caarlos0 merged 4 commits intomainfrom
select-accessible

Conversation

@caarlos0
Copy link
Copy Markdown
Member

closes #639
closes #638

@caarlos0 caarlos0 added bug Something isn't working enhancement New feature or request select labels Apr 29, 2025
@caarlos0 caarlos0 self-assigned this Apr 29, 2025
@caarlos0 caarlos0 requested a review from a team as a code owner April 29, 2025 14:34
@caarlos0 caarlos0 requested review from bashbunni and Copilot and removed request for a team April 29, 2025 14:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the handling of defaults and prompts for select and multiselect inputs. Key changes include introducing an atoi helper to process input strings, updating prompt error messages for clarity, and refining the default value handling logic in select/multiselect fields.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/accessibility/accessibility.go Adds a helper function (atoi) to handle empty string inputs better.
huh_test.go Updates test assertions to use Fatalf in order to fail tests fast.
field_select.go Adjusts default value assignment in select fields by ensuring s.selected is set.
field_multiselect.go Modifies the input condition to catch negative values by using <= instead of ==.
Comments suppressed due to low confidence (2)

huh_test.go:1458

  • [nitpick] Using tb.Fatalf halts the test execution on the first failure, possibly masking subsequent errors. Consider using tb.Errorf if you wish to aggregate multiple assertion failures in a single test run.
tb.Fatalf("expected %v to be equal to %v", a, b)

field_select.go:724

  • Ensure that s.selectOption() reliably sets s.selected before it is used to compute defaultValue. Adding an inline comment or assertion could help clarify the intended behavior and prevent off-by-one errors.
s.selectOption() // make sure s.selected is set

@caarlos0 caarlos0 merged commit 93d2a08 into main Apr 29, 2025
40 checks passed
@caarlos0 caarlos0 deleted the select-accessible branch April 29, 2025 16:56
idx := s.selected + 1
defaultValue = &idx
}
prompt := fmt.Sprintf("Enter a number between %d and %d: ", 1, len(s.options.val))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a note, this change from Input to Enter wasn't also reflected in the multiselect, so they are different now.

Demonstrating Single Select
Favorite cuisine? (default: Italian)
1. Italian
2. Greek
3. Indian
4. Japanese
5. American
Enter a number between 1 and 5: 1

Favorite cuisine: Italian
Demonstrating Multi Select
Favorite cuisines?
Select up to 5 options.
1.   Italian
2.   Greek
3.   Indian
4.   Japanese
5.   American
0.   Confirm selection
Input a number between 0 and 5:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Labels

bug Something isn't working enhancement New feature or request select

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Awkward select message in accessible mode when there's only one option Accessible Select prompt treats no default value (0) as if the default is 1

4 participants