forum: change some LinkButton code to properly work with 'active' attribute

This commit is contained in:
David Sevilla Martin 2020-01-25 10:25:09 -05:00
parent be6a41ad0e
commit d6a4058c28
No known key found for this signature in database
GPG Key ID: F764F1417E16B15F
3 changed files with 13 additions and 18 deletions

View File

@ -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;

View File

@ -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';

View File

@ -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
);
}
}