mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 17:57:04 +08:00
forum: change some LinkButton code to properly work with 'active' attribute
This commit is contained in:
parent
be6a41ad0e
commit
d6a4058c28
|
@ -51,11 +51,10 @@ export default class Component<T extends ComponentProps = any> {
|
|||
* containing all of the `li` elements inside the DOM element of this
|
||||
* component.
|
||||
*
|
||||
* @param {String} [selector] a jQuery-compatible selector string
|
||||
* @returns {jQuery} the jQuery object for the DOM node
|
||||
* @param selector a jQuery-compatible selector string
|
||||
* @final
|
||||
*/
|
||||
$(selector?: string) {
|
||||
$(selector?: string): ZeptoCollection {
|
||||
const $element = $(this.element);
|
||||
|
||||
return selector ? $element.find(selector) : $element;
|
||||
|
|
|
@ -31,8 +31,8 @@ export interface ButtonProps extends ComponentProps {
|
|||
* be used to represent any generic clickable control, like a menu item.
|
||||
*/
|
||||
export default class Button<T extends ButtonProps = ButtonProps> extends Component<T> {
|
||||
view(vnode) {
|
||||
const { children, ...attrs} = vnode.attrs;
|
||||
view() {
|
||||
const { children, ...attrs} = this.props;
|
||||
|
||||
attrs.className = attrs.className || '';
|
||||
attrs.type = attrs.type || 'button';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import Button, {ButtonProps} from './Button';
|
||||
|
||||
interface LinkButtonProps extends ButtonProps {
|
||||
active: boolean;
|
||||
active: string;
|
||||
oncreate: Function;
|
||||
href?: string;
|
||||
}
|
||||
|
@ -23,26 +23,22 @@ export default class LinkButton extends Button<LinkButtonProps> {
|
|||
props.active = this.isActive(props);
|
||||
}
|
||||
|
||||
view(vnode) {
|
||||
const vdom = super.view(vnode);
|
||||
view() {
|
||||
const vdom = super.view();
|
||||
|
||||
vdom.tag = m.route.Link;
|
||||
|
||||
return vdom;
|
||||
}
|
||||
|
||||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
this.props.active = LinkButton.isActive(this.props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a component with the given props is 'active'.
|
||||
*/
|
||||
static isActive(props: LinkButtonProps): boolean {
|
||||
return typeof props.active !== 'undefined'
|
||||
? props.active
|
||||
: m.route.get() === props.href;
|
||||
static isActive(props: LinkButtonProps): string {
|
||||
return String(
|
||||
typeof props.active !== 'undefined'
|
||||
? props.active
|
||||
: m.route.get() === props.href
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user