From 40943aa6fc7b20de450029173b53d4b78db6bf00 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Fri, 24 May 2024 20:33:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/layui.css | 4 ++-- src/modules/form.js | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/css/layui.css b/src/css/layui.css index f9b8d13d..8adecf5a 100644 --- a/src/css/layui.css +++ b/src/css/layui.css @@ -860,8 +860,8 @@ hr.layui-border-black{border-width: 0 0 1px;} :root .layui-form-selected .layui-edge{margin-top: -9px\0/IE9;} .layui-form-selectup dl{top: auto; bottom: 42px;} .layui-select-none{margin: 5px 0; text-align: center; color: #999;} -.layui-select-panel {position: absolute; z-index: 99999999;} -.layui-select-panel dl{position: static; display: block;} +.layui-select-panel-wrap {position: absolute; z-index: 99999999;} +.layui-select-panel-wrap dl{position: relative; display: block; top:0;} .layui-select-disabled .layui-disabled{border-color: #eee !important;} .layui-select-disabled .layui-edge{border-top-color: #d2d2d2} diff --git a/src/modules/form.js b/src/modules/form.js index b506eee4..c866c06f 100644 --- a/src/modules/form.js +++ b/src/modules/form.js @@ -382,6 +382,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){ var TITLE = 'layui-select-title'; var NONE = 'layui-select-none'; var CREATE_OPTION = 'layui-select-create-option'; + var PANEL_WRAP = 'layui-select-panel-wrap' var PANEL_ELEM_DATA = 'layui-select-panel-elem-data'; var selects = elem || elemForm.find('select'); // 各种事件 @@ -410,6 +411,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){ // 展开下拉 var showDown = function(){ if(isAppendToBody){ + // 如果追加面板元素后出现滚动条,触发元素宽度可能会有变化,所以先追加面板元素 reElem.appendTo('body') .show() .css({width: title.width() + 'px'}); @@ -770,9 +772,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){ // 替代元素 var reElem = $(['
'].join('')); + ,(disabled ? ' layui-select-disabled' : '') + '">'].join('')); var triggerElem = $([ '
' @@ -806,14 +806,17 @@ layui.define(['lay', 'layer', 'util'], function(exports){ // 如果已经渲染,则Rerender if(hasRender[0]){ - isAppendToBody && hasRender.data(PANEL_ELEM_DATA).remove(); + if(isAppendToBody){ + var panelWrapElem = hasRender.data(PANEL_ELEM_DATA); + panelWrapElem && panelWrapElem.remove(); + } hasRender.remove(); } if(isAppendToBody){ reElem.append(triggerElem); othis.after(reElem); - var contentWrapElem = $('
').append(contentElem) - reElem.data(PANEL_ELEM_DATA, contentWrapElem) // 将面板元素对象记录在触发元素 data 中 + var contentWrapElem = $('
').append(contentElem); + reElem.data(PANEL_ELEM_DATA, contentWrapElem); // 将面板元素对象记录在触发元素 data 中 events.call(this, contentWrapElem, triggerElem, disabled, isSearch, isCreatable, isAppendToBody); }else{ reElem.append(triggerElem).append(contentElem);