From d6a4058c28bf13116fa0c169ae68b0b1b03ed2da Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Sat, 25 Jan 2020 10:25:09 -0500 Subject: [PATCH] forum: change some LinkButton code to properly work with 'active' attribute --- js/src/common/Component.ts | 5 ++--- js/src/common/components/Button.tsx | 4 ++-- js/src/common/components/LinkButton.tsx | 22 +++++++++------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/js/src/common/Component.ts b/js/src/common/Component.ts index 21d6cbe0d..cca988c88 100644 --- a/js/src/common/Component.ts +++ b/js/src/common/Component.ts @@ -51,11 +51,10 @@ export default class Component { * 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; diff --git a/js/src/common/components/Button.tsx b/js/src/common/components/Button.tsx index aca937e1f..9d22297af 100644 --- a/js/src/common/components/Button.tsx +++ b/js/src/common/components/Button.tsx @@ -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 extends Component { - view(vnode) { - const { children, ...attrs} = vnode.attrs; + view() { + const { children, ...attrs} = this.props; attrs.className = attrs.className || ''; attrs.type = attrs.type || 'button'; diff --git a/js/src/common/components/LinkButton.tsx b/js/src/common/components/LinkButton.tsx index 95288c6e0..659570a60 100644 --- a/js/src/common/components/LinkButton.tsx +++ b/js/src/common/components/LinkButton.tsx @@ -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 { 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 + ); } }