mirror of
https://github.com/flarum/core.git
synced 2025-08-16 13:24:11 +02:00
update: common/components/SelectDropdown
This commit is contained in:
committed by
Franz Liedke
parent
b60309284c
commit
5a244dcfd2
@@ -6,26 +6,26 @@ import icon from '../helpers/icon';
|
|||||||
* button's label is set as the label of the first child which has a truthy
|
* button's label is set as the label of the first child which has a truthy
|
||||||
* `active` prop.
|
* `active` prop.
|
||||||
*
|
*
|
||||||
* ### Props
|
* ### Attrs
|
||||||
*
|
*
|
||||||
* - `caretIcon`
|
* - `caretIcon`
|
||||||
* - `defaultLabel`
|
* - `defaultLabel`
|
||||||
*/
|
*/
|
||||||
export default class SelectDropdown extends Dropdown {
|
export default class SelectDropdown extends Dropdown {
|
||||||
static initProps(props) {
|
initAttrs(attrs) {
|
||||||
props.caretIcon = typeof props.caretIcon !== 'undefined' ? props.caretIcon : 'fas fa-sort';
|
attrs.caretIcon = typeof attrs.caretIcon !== 'undefined' ? attrs.caretIcon : 'fas fa-sort';
|
||||||
|
|
||||||
super.initProps(props);
|
super.initAttrs(attrs);
|
||||||
|
|
||||||
props.className += ' Dropdown--select';
|
attrs.className += ' Dropdown--select';
|
||||||
}
|
}
|
||||||
|
|
||||||
getButtonContent() {
|
getButtonContent(attrs, children) {
|
||||||
const activeChild = this.props.children.filter((child) => child.props.active)[0];
|
const activeChild = children.filter((child) => child.attrs.active)[0];
|
||||||
let label = (activeChild && activeChild.props.children) || this.props.defaultLabel;
|
let label = (activeChild && activeChild.children) || attrs.defaultLabel;
|
||||||
|
|
||||||
if (label instanceof Array) label = label[0];
|
if (label instanceof Array) label = label[0];
|
||||||
|
|
||||||
return [<span className="Button-label">{label}</span>, icon(this.props.caretIcon, { className: 'Button-caret' })];
|
return [<span className="Button-label">{label}</span>, icon(attrs.caretIcon, { className: 'Button-caret' })];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user