fix selected state of select boxes (#19743)

* fix the selected state

* add comments

* validate parameters
This commit is contained in:
Alan Ren
2022-06-15 20:41:07 -07:00
committed by GitHub
parent b980fe1106
commit e24f316ab7
3 changed files with 5 additions and 1 deletions

View File

@@ -315,6 +315,8 @@ export class Dropdown extends Disposable implements IListVirtualDelegate<string>
private _updateDropDownList(): void {
this._selectList.splice(0, this._selectList.length, this._dataSource.filteredValues.map(v => { return { text: v }; }));
const selectedIndex = this._dataSource.filteredValues.indexOf(this.value);
this._selectList.setSelection(selectedIndex !== -1 ? [selectedIndex] : []);
let width = this._inputContainer.clientWidth;

View File

@@ -1279,7 +1279,8 @@ export class List<T> implements ISpliceable<T>, IThemable, IDisposable {
private _options: IListOptions<T> = DefaultOptions
) {
const role = this._options.accessibilityProvider && this._options.accessibilityProvider.getWidgetRole ? this._options.accessibilityProvider?.getWidgetRole() : 'list';
this.selection = new SelectionTrait(role !== 'listbox');
// {{SQL CARBON EDIT}} - Change the parameter from 'role !== listbox' to 'role !== list', according to the doc https://www.w3.org/WAI/PF/HTML/wiki/RoleAttribute, list role is non-interactive.
this.selection = new SelectionTrait(role !== 'list');
mixin(_options, defaultStyles, false);

View File

@@ -271,6 +271,7 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
// Populate select list for non-native select mode
if (this.selectList) {
this.selectList.splice(0, this.selectList.length, this.options);
this.selectList?.setSelection(this.selected !== -1 ? [this.selected] : []); // {{SQL CARBON EDIT}} - Set the selected indexes.
}
}