From 44e54e586efd102476e7dc5fa3f4d8753632e1d3 Mon Sep 17 00:00:00 2001 From: topwms Date: Sun, 13 Apr 2025 23:05:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(tabs):=20=E4=B8=BA=20tabs.add=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20active=20=E9=80=89=E9=A1=B9=20(#2607)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * tabs.add新增chang 是否将插入项切换为当前标签,l默认为true * change参数 * feat: 将 `change` 选项更改命名为 `active` * chore: 修改 closable 选项 JSDoc 类型 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com> --- docs/tabs/index.md | 1 + src/modules/tabs.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/tabs/index.md b/docs/tabs/index.md index ed9e35ab..a38e3a41 100644 --- a/docs/tabs/index.md +++ b/docs/tabs/index.md @@ -110,6 +110,7 @@ tabs.render({ | id | 标签的 `lay-id` 属性值 | string | - | | index | 活动标签的索引或 `lay-id` 属性值,默认取当前选中标签的索引 | number | - | | mode | 标签的插入方式。支持以下可选值: | string | `append` | +| active | 是否将新增项设置为活动标签 | boolean | `true` | | closable | 标签是否可关闭。初始值取决于 `options.closable` | boolean | `false` | | headerItem | 自定义标签头部元素,如 `headerItem: '
  • '` | string | - | | bodyItem | 自定义标签内容元素,如 `bodyItem: '
    '` | string | - | diff --git a/src/modules/tabs.js b/src/modules/tabs.js index 263186fd..c37401fe 100644 --- a/src/modules/tabs.js +++ b/src/modules/tabs.js @@ -173,7 +173,8 @@ layui.define('component', function(exports) { * @param {string} opts.id - 标签的 lay-id 属性值 * @param {string} [opts.index] - 活动标签索引,默认取当前选中标签的索引 * @param {('append'|'prepend'|'after'|'before')} [opts.mode='append'] - 标签插入方式 - * @param {string} [opts.closable] - 标签是否可关闭。初始值取决于 options.closable + * @param {boolean} [opts.active] - 是否将新增项设置为活动标签 + * @param {boolean} [opts.closable] - 标签是否可关闭。初始值取决于 options.closable * @param {string} [opts.headerItem] - 自定义标签头部元素 * @param {string} [opts.bodyItem] - 自定义标签内容元素 * @param {Function} [opts.done] - 标签添加成功后执行的回调函数 @@ -185,6 +186,11 @@ layui.define('component', function(exports) { var newHeaderItem = that.renderHeaderItem(opts); var newBodyItem = that.renderBodyItem(opts); + // 选项默认值 + opts = $.extend({ + active: true + }, opts); + // 插入方式 if (/(before|after)/.test(opts.mode)) { // 在活动标签前后插入 var data = that.data(); @@ -202,8 +208,12 @@ layui.define('component', function(exports) { container.body.elem[mode](newBodyItem); } - // 将插入项切换为当前标签 - that.change(newHeaderItem, true); + // 是否将新增项设置为活动标签 + if (opts.active) { + that.change(newHeaderItem, true); + } else { + that.roll('auto'); + } // 回调 var params = that.data();