Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-apricots-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/ds-core': patch
---

**select**: select first option as default and value can be reset
10 changes: 5 additions & 5 deletions e2e/cypress/component/bal-select.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('bal-select', () => {

it('should select option with the key entry plus enter', () => {
cy.get('bal-select').find('.bal-select__control__input').click()
cy.get('bal-select').type('{downArrow}').type('{enter}')
cy.get('bal-select').type('{enter}')

cy.get('@balChange').should('have.been.calledOnce')
cy.get('@balChange').shouldHaveEventDetail('v1995')
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('bal-select', () => {

cy.get('bal-select').find('.bal-select__control__input').click()
cy.get('bal-select').find('.bal-select__control__input').type('{1}').type('{9}').type('{9}')
cy.get('bal-select').type('{downArrow}').type('{enter}').blur({ force: true })
cy.get('bal-select').type('{enter}').blur({ force: true })

cy.get('@balChange').should('have.been.calledOnce')
cy.get('@balChange').shouldHaveEventDetail('v1995')
Expand All @@ -130,7 +130,7 @@ describe('bal-select', () => {
cy.get('bal-select').invoke('attr', 'multiple', true)

cy.get('bal-select').find('.bal-select__control__selections').click()
cy.get('bal-select').type('{downArrow}').type('{enter}')
cy.get('bal-select').type('{enter}')
cy.get('bal-select').type('{downArrow}').type('{enter}')

cy.get('@balChange').should('have.been.callCount', 2)
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('bal-select', () => {
cy.get('bal-select').invoke('attr', 'multiple', true).invoke('attr', 'typeahead', true)

cy.get('bal-select').find('.bal-select__control__selections').click()
cy.get('bal-select').type('{downArrow}').type('{enter}')
cy.get('bal-select').type('{enter}')
cy.get('bal-select').type('{downArrow}').type('{enter}')

cy.get('@balChange').should('have.been.callCount', 2)
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('bal-select', () => {

cy.get('bal-select').find('.bal-select__control__selections').click()
cy.get('bal-select').find('.bal-select__control__input').type('{1}').type('{9}').type('{9}')
cy.get('bal-select').type('{downArrow}').type('{enter}')
cy.get('bal-select').type('{enter}')

cy.get('@balChange').should('have.been.callCount', 1)
cy.get('@balChange').shouldHaveEventDetail(['v1995'])
Expand Down
4 changes: 2 additions & 2 deletions e2e/cypress/e2e/base/bal-select.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('bal-select', () => {
describe('typeahead', () => {
it('should clear select and search for the Black Widow', () => {
cy.getByTestId('typeahead').clear().blur()
cy.getByTestId('typeahead').type('Black{downArrow}{enter}').blur().should('have.value', 'Black Widow')
cy.getByTestId('typeahead').type('Black{enter}').blur().should('have.value', 'Black Widow')
})
})

Expand All @@ -48,7 +48,7 @@ describe('bal-select', () => {
it('should restore initial value when it has been reset', () => {
// First we change the initial values to 1995
cy.getByTestId('reset-basic').click().select('1995')
cy.getByTestId('reset-typeahead').clear().type('1995{downArrow}{enter}')
cy.getByTestId('reset-typeahead').clear().type('1995{enter}')
cy.getByTestId('reset-multiple').click().balSelectFindOptions().first().click()
cy.getByTestId('reset-multiple').balSelectFindOptions().eq(1).click()
cy.getByTestId('reset-multiple').balSelectFindOptions().eq(2).click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@
min-height: 2rem

.bal-dropdown__root--theme-purple:not(.bal-dropdown__root--theme-purple-expanded)

border: none
background: var(--bal-color-background-grey-light)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
--bal-dropdown-control-input-multiple-background-read-only-selection: transparent
--bal-dropdown-control-input-option-background: transparent
--bal-dropdown-control-input-option-background-selected: var(--bal-color-primary-1)
--bal-dropdown-control-input-option-background-focused: var(--bal-color-grey-2)
--bal-dropdown-control-input-option-background-hover: var(--bal-color-grey-2)
--bal-dropdown-control-input-option-background-focused: var(--bal-color-grey-3)
--bal-dropdown-control-input-option-background-hover: var(--bal-color-grey-3)
//
// border radius
--bal-dropdown-control-border-radius: var(--bal-form-field-control-radius)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//
// background colors
--bal-option-background: var(--bal-color-white)
--bal-option-background-hovered: var(--bal-color-grey-2)
--bal-option-background-hovered: var(--bal-color-grey-3)
--bal-option-background-selected: var(--bal-color-primary-1)
--bal-option-background-selected-hovered: #dddfeb
--bal-option-background-invalid: var(--bal-color-danger-1)
Expand Down
46 changes: 24 additions & 22 deletions packages/core/src/components/bal-select/bal-select.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import {
Component,
ComponentInterface,
Element,
Event,
EventEmitter,
h,
Host,
State,
Listen,
Method,
Prop,
State,
Watch,
EventEmitter,
Event,
Method,
Element,
Listen,
ComponentInterface,
} from '@stencil/core'
import isNil from 'lodash.isnil'
import { debounce, deepReady, isDescendant, rIC, waitAfterIdleCallback } from '../../utils/helpers'
import { ariaBooleanToString } from '../../utils/aria'
import { areArraysEqual } from '../../utils/array'
import { isArrowDownKey, isArrowUpKey, isEnterKey, isEscapeKey, isSpaceKey, isBackspaceKey } from '../../utils/keyboard'
import { BEM } from '../../utils/bem'
import { BalAriaForm, BalAriaFormLinking, defaultBalAriaForm } from '../../utils/form'
import { stopEventBubbling } from '../../utils/form-input'
import { debounce, deepReady, isDescendant, rIC, waitAfterIdleCallback } from '../../utils/helpers'
import { isArrowDownKey, isArrowUpKey, isBackspaceKey, isEnterKey, isEscapeKey, isSpaceKey } from '../../utils/keyboard'
import { Loggable, Logger, LogInstance } from '../../utils/log'
import { BalOptionValue } from './utils/bal-option.type'
import {
addValue,
findLabelByValue,
Expand All @@ -29,12 +35,6 @@ import {
validateAfterBlur,
} from './utils/utils'
import { watchForOptions } from './utils/watch-options'
import { BalOptionValue } from './utils/bal-option.type'
import { stopEventBubbling } from '../../utils/form-input'
import { BEM } from '../../utils/bem'
import { Loggable, Logger, LogInstance } from '../../utils/log'
import { BalAriaForm, BalAriaFormLinking, defaultBalAriaForm } from '../../utils/form'
import { ariaBooleanToString } from '../../utils/aria'

export interface BalOptionController extends BalOptionValue {
id: string
Expand Down Expand Up @@ -408,7 +408,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
*/
@Method()
async clear() {
this.focusIndex = -1
this.focusIndex = 0
if (this.inputElement) {
this.updateInputValue('')
this.updateRawValue([], isHuman)
Expand Down Expand Up @@ -568,8 +568,8 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
********************************************************/
private updateFocusTimer?: NodeJS.Timeout
private updateFocus() {
if (this.focusIndex < -1) {
this.focusIndex = -1
if (this.focusIndex < 0) {
this.focusIndex = 0
}

const visibleOptions = this.optionArray
Expand All @@ -589,7 +589,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
}
}
} else {
this.focusIndex = -1
this.focusIndex = 0
}
}

Expand Down Expand Up @@ -787,6 +787,8 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
label = valuesArray.join(', ')
}
return this.updateInputValue(label)
} else {
return this.updateInputValue('')
}
}
return Promise.resolve()
Expand Down Expand Up @@ -832,7 +834,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
if (this.isPopoverOpen) {
this.updateFocus()
} else {
this.focusIndex = -1
this.focusIndex = 0
if (this.multiple && this.typeahead) {
this.updateInputValue('')
}
Expand Down Expand Up @@ -886,7 +888,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
if (this.disabled || this.readonly) {
preventDefault(ev)
} else {
this.focusIndex = -1
this.focusIndex = 0
this.balInputClick.emit(ev)

if (this.typeahead) {
Expand Down Expand Up @@ -927,7 +929,7 @@ export class Select implements ComponentInterface, Loggable, BalAriaFormLinking
this.popoverElement.present()
}

this.focusIndex = -1
this.focusIndex = 0
this.updateFocus()
preventDefault(ev)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
--bal-select-control-input-multiple-background-read-only-selection: transparent
--bal-select-control-input-option-background: transparent
--bal-select-control-input-option-background-selected: var(--bal-color-primary-1)
--bal-select-control-input-option-background-focused: var(--bal-color-grey-2)
--bal-select-control-input-option-background-hover: var(--bal-color-grey-2)
--bal-select-control-input-option-background-focused: var(--bal-color-grey-3)
--bal-select-control-input-option-background-hover: var(--bal-color-grey-3)
//
// border radius
--bal-select-control-border-radius: var(--bal-form-field-control-radius)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
"node_modules",
"tmp"
]
}
}