Tabs within display:none get empty labels - Ext JS

本文介绍了一种在ExtJS中解决TabPanel组件显示问题的方法,通过使用隐藏类而非display:none属性来避免尺寸计算错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hi Jack and all,

When I build a TabPanel inside of a hidden div (display:none). This behavior is different from previous releases up to 1.0alpha2 (though behavior wasn't what I expected in those versions either). Seems like a bug, but when I mentioned those problems in earlier versions in the bugs forum it was moved to help--so maybe it's actually intended behavior?

Here's the code to reproduce the problem:

<!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<link rel='stylesheet' type='text/css' href='/ext-1.0-alpha3/resources/css/ext-all.css' />
<link rel='stylesheet' type='text/css' href='/unauthenticated/layout.css' />
<script type='text/javascript' src='/ext-1.0-alpha3/yui-utilities.js'></script>
<script type='text/javascript' src='/ext-1.0-alpha3/ext-yui-adapter.js'></script>
<script type='text/javascript' src='/ext-1.0-alpha3/ext-all.js'></script>
<title>Tabs Test Page</title>
</head>
<body>
<script>
// Open or close a hidden section
function hidden_opener(divid)
{
var divobj = Ext.Element.get(divid);
var dh = Ext.DomHelper;
if (divobj.getStyle("display")=="inline") {
  dh.applyStyles(divid, "display:none");
  }
else {
  dh.applyStyles(divid, "display:inline");
  }
}
</script>

<script>
Tabs = function() {
  return {
    init : function(){
      var tabs = new Ext.TabPanel('simplemode');
      tabs.addTab('simple', "Basic mode");
      tabs.addTab('complex', "Advanced mode");
      tabs.activate('simple');
    }
  }
}();
Ext.EventManager.onDocumentReady(Tabs.init, Tabs, true);
</script>
:hidden_opener('hiddendiv')" target="_blank">Open/Close
<div id='hiddendiv' style="display: none;">
  <div id='simplemode'>
    <div id='simple' class='tab-content'>
      Blah Blah
    </div>
    <div id='complex' class='tab-content'>
      Nah Nah
    </div>

  </div>
</div>
</body></html>
If the div starts display: inline, the problem doesn't exhibit.

Am I just going about things all wrong? (I don't get to decide when elements get added to the display, so I can't draw the tabs when the div gets opened out.)

Thanks for any pointers you can provide.
Reply With Quote
  #2  
Old 03-13-2007, 02:22 AM
Default

display:none for any component which does sizing calculations isn't supported. There are a few alternatives to display:none which aren't so volatile, I would recommend trying an alternative. Like, using a hidden class.

.hidden {
    visibility:hidden;
    position:absolute;
    top:-2000px;
    left:-2000px;
}
Reply With Quote
  #3  
Old 03-13-2007, 02:30 AM
Default

You rock, Jack!

Here's the modified version, using the Element toggleClass method (just in case anyone is banging their heads on this like I've been):

<!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<link rel='stylesheet' type='text/css' href='/ext-1.0-alpha3/resources/css/ext-all.css' />
<link rel='stylesheet' type='text/css' href='/unauthenticated/layout.css' />
<script type='text/javascript' src='/ext-1.0-alpha3/yui-utilities.js'></script>
<script type='text/javascript' src='/ext-1.0-alpha3/ext-yui-adapter.js'></script>
<script type='text/javascript' src='/ext-1.0-alpha3/ext-all.js'></script>
<title>Tabs Test Page</title>
</head>
<body>
<script>
// Open or close a hidden section
function hidden_opener(divid)
{
var divobj = Ext.Element.get(divid);
divobj.toggleClass("hidden");
}
</script>

<script>
Tabs = function() {
  return {
    init : function(){
      var tabs = new Ext.TabPanel('simplemode');
      tabs.addTab('simple', "Basic mode");
      tabs.addTab('complex', "Advanced mode");
      tabs.activate('simple');
    }
  }
}();
Ext.EventManager.onDocumentReady(Tabs.init, Tabs, true);
</script>
<style>
.hidden {
    visibility:hidden;
    position:absolute;
    top:-2000px;
    left:-2000px;
}
</style>
:hidden_opener('hiddendiv')" target="_blank">Open/Close
<div id='hiddendiv' class="hidden">
  <div id='simplemode'>
    <div id='simple' class='tab-content'>
      Blah Blah
    </div>
    <div id='complex' class='tab-content'>

      Nah Nah
    </div>
  </div>
</div>
</body></html>
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值