This library provides material design select functionality implemented using extended typescript
Install using npm
npm i @ohos/material-select
Material select library provides three types of select boxes:-
MaterialSelect - Provides single option selection functionality.
MultipleSelect - Provides multiple option selection functionality.
DotMenu - Provides dot menu functionality.
- Import files and code dependencies
import { MaterialSelect, MenuOption } from '@ohos/material-select'
import { MultipleSelect, MultipleMenuOption } from '@ohos/material-select'
import { DotMenu, DotMenuOption } from '@ohos/material-select'
- Initialize select model data
private singleSelectModel:MaterialSelect.Model = new MaterialSelect.Model('Title', 'Placeholder')
private multipleSelectModel: MultipleSelect.Model = new MultipleSelect.Model('Title')
private dotModel: DotMenu.Model = new DotMenu.Model()
- Initialize select menu model data
private singleSelectMenuModel: MaterialSelect.MenuModel = new MaterialSelect.MenuModel()
private multipleSelectMenuModel: MultipleSelect.MenuModel = new MultipleSelect.MenuModel()
private dotMenuModel: DotMenu.MenuModel = new DotMenu.MenuModel()
- Initialize menus for select components
private single: MenuOption[] = [
new MenuOption("Option 1", 1),
new MenuOption("Option 2", "2")
]
private multiple: MultipleMenuOption[] = [
new MultipleMenuOption("Option 1", 1),
new MultipleMenuOption("Option 2", "2", true)
]
private dot: DotMenuOption[] = [
new DotMenuOption("Preview", 1),
new DotMenuOption("Download", "2", $r("app.media.download")
]
- Code for creating single selection component
MaterialSelect({
menu: this.single,
onSelect: (it: MenuOption) => {},
model: this.singleSelectModel
})
- Code for creating multiple selection component
MultipleSelect({
menu: this.multiple,
onSelect: (it: MultipleMenuOption[]) => {},
model: this.multipleSelectModel,
menuModel: this.singleSelectMenuModel
})
- Code for creating dot menu component
DotMenu({
menu: this.dotMenu,
onSelect: (it: DotMenuOption) => {},
model: this.dotModel,
menuModel: this.dotMenuModel
})
Supports OpenHarmony API version 9
If you find any problems during usage, you can submit an Issue to us. Of course, we also welcome you to send us PR.
This project is based on Apache License 2.0, please enjoy and participate in open source freely.
- BorderRadius property in MenuModel does not change the border radius of popup menu.
- Popup menu of MultipleSelect disappears after single click.
Design by : Sarthak Gothalyan