diff --git a/src/password-input/index.js b/src/password-input/index.js index d8084d5a4..e942a2ac7 100644 --- a/src/password-input/index.js +++ b/src/password-input/index.js @@ -27,10 +27,10 @@ export default createComponent({ emits: ['focus'], setup(props, { emit }) { - function onTouchStart(event) { + const onTouchStart = (event) => { event.stopPropagation(); emit('focus', event); - } + }; return () => { const { mask, value, length, gutter, focused, errorInfo } = props; diff --git a/src/tree-select/index.js b/src/tree-select/index.js index 3ecb0a07d..1c304cfbe 100644 --- a/src/tree-select/index.js +++ b/src/tree-select/index.js @@ -44,18 +44,61 @@ export default createComponent({ ], setup(props, { emit, slots }) { - return function () { - const { items, height, activeId, selectedIcon, mainActiveIndex } = props; + const isMultiple = () => Array.isArray(props.activeId); - const selectedItem = items[+mainActiveIndex] || {}; - const subItems = selectedItem.children || []; - const isMultiple = Array.isArray(activeId); + const isActiveItem = (id) => { + return isMultiple() + ? props.activeId.indexOf(id) !== -1 + : props.activeId === id; + }; - function isActiveItem(id) { - return isMultiple ? activeId.indexOf(id) !== -1 : activeId === id; - } + const renderSubItem = (item) => { + const onClick = () => { + if (item.disabled) { + return; + } - const Navs = items.map((item) => ( + let activeId; + if (isMultiple()) { + activeId = props.activeId.slice(); + + const index = activeId.indexOf(item.id); + + if (index !== -1) { + activeId.splice(index, 1); + } else if (activeId.length < props.max) { + activeId.push(item.id); + } + } else { + activeId = item.id; + } + + emit('update:activeId', activeId); + emit('click-item', item); + }; + + return ( +
+ {item.text} + {isActiveItem(item.id) && ( + + )} +
+ ); + }; + + const renderSidebar = () => { + const Items = props.items.map((item) => ( )); - function Content() { - if (slots.content) { - return slots.content(); - } - - return subItems.map((item) => ( -
{ - if (!item.disabled) { - let newActiveId = item.id; - if (isMultiple) { - newActiveId = activeId.slice(); - - const index = newActiveId.indexOf(item.id); - - if (index !== -1) { - newActiveId.splice(index, 1); - } else if (newActiveId.length < props.max) { - newActiveId.push(item.id); - } - } - - emit('update:activeId', newActiveId); - emit('click-item', item); - } - }} - > - {item.text} - {isActiveItem(item.id) && ( - - )} -
- )); - } - return ( -
- { - emit('update:mainActiveIndex', index); - emit('click-nav', index); - }} - > - {Navs} - -
{Content()}
-
+ { + emit('update:mainActiveIndex', index); + emit('click-nav', index); + }} + > + {Items} + ); }; + + const renderContent = () => { + if (slots.content) { + return slots.content(); + } + + const selected = props.items[+props.mainActiveIndex] || {}; + if (selected.children) { + return selected.children.map(renderSubItem); + } + }; + + return () => ( +
+ {renderSidebar()} +
{renderContent()}
+
+ ); }, });