Skip to content

Commit

Permalink
refactor: rename AtLeast to Minumum
Browse files Browse the repository at this point in the history
  • Loading branch information
yutasb committed Jul 28, 2024
1 parent 4b07d98 commit 5108159
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions field_multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type MultiSelect[T comparable] struct {
filterable bool
filteredOptions []Option[T]
limit int
atLeast int
minimum int
height int

// error handling
Expand Down Expand Up @@ -175,9 +175,9 @@ func (m *MultiSelect[T]) Limit(limit int) *MultiSelect[T] {
return m
}

// AtLeast sets the minimum number of options that must be selected.
func (m *MultiSelect[T]) AtLeast(atLeast int) *MultiSelect[T] {
m.atLeast = atLeast
// Minimum sets the minimum of the multi-select field.
func (m *MultiSelect[T]) Minimum(minimum int) *MultiSelect[T] {
m.minimum = minimum
return m
}

Expand Down Expand Up @@ -386,8 +386,8 @@ func (m *MultiSelect[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.updateValue()
case key.Matches(msg, m.keymap.Prev):
m.updateValue()
if m.atLeast > 0 && m.numSelected() < m.atLeast {
m.err = fmt.Errorf("you must select at least %d options", m.atLeast)
if m.minimum > 0 && m.numSelected() < m.minimum {
m.err = fmt.Errorf("you must select at least %d options", m.minimum)
return m, nil
}
m.err = m.validate(m.accessor.Get())
Expand All @@ -397,8 +397,8 @@ func (m *MultiSelect[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, PrevField
case key.Matches(msg, m.keymap.Next, m.keymap.Submit):
m.updateValue()
if m.atLeast > 0 && m.numSelected() < m.atLeast {
m.err = fmt.Errorf("you must select at least %d options", m.atLeast)
if m.minimum > 0 && m.numSelected() < m.minimum {
m.err = fmt.Errorf("you must select at least %d options", m.minimum)
return m, nil
}
m.err = m.validate(m.accessor.Get())
Expand Down
2 changes: 1 addition & 1 deletion huh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestForm(t *testing.T) {
).
Value(&order.Beverages.Name).
Filterable(true).
AtLeast(2),
Minimum(2),
),

// Gather final details for the order.
Expand Down

0 comments on commit 5108159

Please sign in to comment.