Developer Network Home - Help

Yahoo! UI Library: Container

Yahoo! UI Library: Container

The Container family of components is designed to enable developers to create different kinds of content-containing modules on the web. Module and Overlay are the most basic containers, and they can be used directly or extended to build custom containers. Also part of the Container family are four UI controls that extend Module and Overlay: Tooltip, Panel, Dialog, and SimpleDialog.

2.3.1 UPGRADE NOTE: Z-INDEX & POSITION

To help prevent the occurrence of "Operation Aborted" errors in IE, Module/Overlay based controls (the Container family and Menu) which are rendered to document.body are now inserted as the first child of the body element. Prior to 2.3.1, they were appended as the last child of the body element. The same applies to the associated iframe shim if it is enabled.

If you are setting an xy position and setting a z-index to force the control to lie on top of other elements on the page, then the change should have no impact.

However, if you're relying on the order of the elements in the DOM to stack and position Overlay based controls rendered to document.body, you may see changes when upgrading to 2.3.1:

  • Z-Index: If the z-index of the control (or the associated iframe shim, which will be set to a z-index one less than that of the control) is the same as another positioned element on the page, the control (or iframe shim) will be stacked underneath the positioned element if they overlap. The z-index of the control will need to be bumped up to resolve the issue.
  • Position: If you're not setting a specific xy co-ordinate for the control, it's position may change going from 2.3.0 to 2.3.1 depending on the layout of your page. A specific xy co-ordinate will need to be set to resolve the issue.

In order to reduce the impact of the change in DOM order on common use case scenarios, the default z-index for Overlay based controls has been increased from 1 (in 2.3.0) to 2 (in 2.3.1), so that by default the Overlay, iframe shim and mask (if applicable) lie above positioned page elements with no specific z-index set (z-index:auto).

See the Release Notes for detailed information about this change, how to revert to 2.3.0 behavior if required, and other z-index fixes applied to 2.3.1

The Container Family

Module

Module enables you to create a JavaScript object representation of any HTML module marked up using Standard Module Format. With Module you can manipulate existing modules on your pages or to create new ones dynamically. A Module has no predefined styles or CSS associated with it and must be styled manually.

Overlay

Overlay extends Module. An Overlay represents a Module that you wish to position absolutely on the page, one that will float above the document's inline content without affecting page flow. As with Module, Overlay has no predefined styles or CSS associated with it and must be styled manually.

Tooltip

The YUI Tooltip ControlTooltip extends Overlay and is used to generate small, floating boxes of the kind often used to provide contextual help in operating systems. Tooltips are almost always created dynamically based on user interaction (such as hovering over an element with the mouse). The Tooltip control comes with a predefined default CSS file to handle styling.

The YUI Panel ControlPanel

Panel extends Overlay and mimics the familiar behavior of an operating system window. Panels have built-in draggability, modality, drop shadow, matting, and many other configurable properties. Panels are primarily used to display informational content and require no action from the user; the user's expected interaction with Panel is merely to drag or dismiss the window.

The YUI Dialog ControlDialog

Dialog extends Panel and behaves like a system dialog. A Dialog instance must contain a browser form. If one is not included, it is automatically created. Dialog provides built-in features for submitting form data in three ways: asynchronously using Connection Manager, through a normal form submission, or with a script that listens for and reacts to the form's posting solely within the page.

SimpleDialog

The YUI SimpleDialog ControlSimpleDialog extends Dialog and behaves like an operating system dialog (modal or non-modal). The look and feel of a SimpleDialog instance is similar to that of a Panel, but with SimpleDialog the user responds to a question with a single answer— OK/Cancel, Yes/No, and so on. Event handlers are attached to the buttons in a SimpleDialog instance to enable your script to respond to whatever choice the user has made.

Getting Started

We provide two separate builds of Container: One build (continer_core.js) includes just the two foundation classes, Module and Overlay, and a second, larger build (container.js) contains the entire Container family, including the four controls based on Module and Overlay: Tooltip, Panel, Dialog and SimpleDialog. You can optimize your use of the Container family by understanding the Container object model and using the correct build in your page:

Container_Core (Foundations Only) Container (Foundations + UI controls)
Module Module
Overlay Overlay
  Tooltip
  Panel
  Dialog
  SimpleDialog

To use the Container family of components, include the following source code in your web page:

And the following CSS files:

If you are not using Tooltip, Panel, Dialog, or SimpleDialog, you may substitute container-min.js with the smaller container_core-min.js file:

Note that a CSS file is not required if you're only using container_core-min.js, however for the Overlay to operate as designed, it does need to be positioned absolutely.

YUI dependency configurator.

YUI Dependency Configurator:

Instead of copying and pasting the filepaths above, try letting the YUI dependency Configurator determine the optimal file list for your desired components; the Configurator uses YUI Loader write out the full HTML for including the precise files you need for your implementation.

Note: If you wish to include this component via the YUI Loader, its module name is container. (Click here for the full list of module names for YUI Loader.)

Where these files come from: The files included using the text above will be served from Yahoo! servers; see "Serving YUI Files from Yahoo!" for important information about this service. JavaScript files are minified, meaning that comments and white space have been removed to make them more efficient to download. To use the full, commented versions or the -debug versions of YUI JavaScript files, please download the library distribution and host the files on your own server.

Order matters: As is the case generally with JavaScript and CSS, order matters; these files should be included in the order specified above. If you include files in the wrong order, errors may result.

Using "CSS skins": One of the files listed above contains a CSS "skin" for the Container Family. For this skin CSS to work correctly, you will need to apply the CSS class "yui-skin-sam" to an element that is a parent of the element in which the component lives. You can usually accomplish this simply by putting the class on the <body> tag:

<body class="yui-skin-sam">

For more information on skinning YUI components and making use of default skins, see our Understanding YUI Skins article here on the website.

Container Object Model

Known Issues

  • "Sam" skin Panel missing left and right borders when declared with a height

    If the height of a Panel instance exceeds the total height of its header, body and footer elements, the space not filled with content will lack a left and right border. Therefore, to set a Panel instance to a fixed height when using the "Sam" skin, apply the desired height to the body element, taking into account the height of the header and footer elements. To set the height of a Panel instance's body via CSS:

    Or via JavaScript:

  • Elements with scrollbars poke through Overlay instances floating above them

    There is a bug in Gecko-based browsers for Mac OS X where an element's scrollbars will poke through absolutely positioned elements floating above them. To fix this problem the "overflow" property of an Overlay instance's root element is toggled between "hidden" and "auto" (through the application and removal of the "hide-scrollbars" and "show-scrollbars" CSS classes) as its "visibility" configuration property is toggled between "false" and "true."

    PLEASE NOTE:

    1. The "hide-scrollbars" and "show-scrollbars" CSS classes classes are applied only for Gecko on Mac OS X and are added/removed to/from the Overlay's root HTML element (DIV) via the "hideMacGeckoScrollbars" and "showMacGeckoScrollbars" methods of YAHOO.widget.Overlay.
    2. For Panel (and its subclasses) it is the underlay element, not the root element, whose "overflow" property is toggled between "hidden" and "auto." The underlay element therefore acts as a shim to correct the scrollbar problem.
    3. For Tooltip instances using the "Sam" skin it is the shadow element, not the root element, whose "overflow" property is toggled between "hidden" and "auto." The shadow element therefore acts as a shim to correct the scrollbar problem.
    4. Once the fix is applied the bug will reappear if the window loses focus. This can be remedied via Javascript by hiding and showing the Overlay instance when the window receives focus:
    For more information see the Mozilla bug report for this issue.
  • Scrollbars remain visible after an Overlay is hidden

    There is a bug in Gecko-based browsers for Mac OS X where an element's scrollbars and the scrollbars of its child nodes remain visible when its "visibility" property property is set to "hidden." To fix this problem, the "overflow" property of an Overlay instance's root element and child nodes is toggled between "hidden" and "auto" (through the application and removal of the "hide-scrollbars" and "show-scrollbars" CSS classes) as its "visibility" configuration property is toggled between "false" and "true."

    PLEASE NOTE:

    1. The "hide-scrollbars" and "show-scrollbars" CSS classes classes are applied only for Gecko on Mac OS X and are added/removed to/from the Overlay's root HTML element (DIV) via the "hideMacGeckoScrollbars" and "showMacGeckoScrollbars" methods of YAHOO.widget.Overlay.
    2. There may be instances where the CSS for a web page or application contains style rules whose specificity override the rules implemented by the Container CSS files to fix this bug. In such cases, is necessary to leverage the provided "hide-scrollbars" and "show-scrollbars" classes to write custom style rules to guard against this bug. For example: To fix the scrollbars issue for an Overlay instance with an id of "myoverlay" whose body element has scrollbars applied by default: To fix the scrollbars issue for a Panel instance with an id of "mypanel" whose body element has scrollbars applied by default:
    For more information see the Mozilla bug report for this issue.
  • Flash Movies appear on top of Overlay instances

    Flash movies can appear on top of Overlay instances in IE and Gecko-based browsers. To fix this problem, set the "wmode" of the Flash movie to either "transparent" or "opaque" as indicated below:

    Via the <object> tag:
    Via the <embed> tag:
    For more information see the Adobe TechNote on this issue.
  • Overlay instances not rendered at correct z-index in IE

    In IE, when an Overlay instance is rendered inside a relatively positioned element the z-index of the Overlay instance is now relative to its relatively positioned parent element. This is not a bug in the Overlay class, but rather a bug in IE where relatively positioned elements establish a new stacking context for their child nodes. To avoid this bug it is recommend that all Overlay instances that need to be able to float above any other element in the document be made direct descendants of the <body> element.

    [Read more on this issue.]
  • Header elements for Panel instances using "Sam" skin shrinkwrap in IE 7

    In IE 7 (Standards Mode) if a Panel instance is created without specifying a value for the "width" configuration property the width of the Panel's header element will shrinkwrap to the width of its text node. To avoid triggering this bug in IE always specify a value for the "width" configuration property when using Panel.

  • Panel instances render at 100% of the browser viewport

    In IE 7 (Quirks Mode) and IE 6 (Quirks Mode and Standards Mode) if any of the child nodes of a Panel instance's root element have "layout" and no value has been specified for the "width" configuration property, the Panel will render at 100% of the width of browser's viewport. This bug will manifest when using the "Sam" skin as layout is applied to the header, body and footer elements (by setting the CSS "zoom" property of the element to "1" ) in order to get the negative margins required for the rounded corners to render correctly. To avoid triggering this bug in IE always specify a value for the "width" configuration property when using Panel.

    For more information on IE and layout, see MSDN's hasLayout reference.
  • Panel instances render at 2px wider when using "Sam" skin

    For the "Sam" skin a Panel instance's rounded corners are created via the application of negative 1px left and right margins on the header, body and footer elements. These negative margins will cause a Panel instance to be rendered at 2px wider than the value specified by the "width" configuration property. Therefore, when using the "Sam" skin consider the negative left and right margins and subtract 2 from the value passed to the "width" configuration property in order to have the Panel render at the desired width. For example, to render a Panel 300px wide, pass a value of "298px" to the "width" configuration property.

  • In IE, borders for tables with border-collapse:collapse remain visible when the container is hidden

    If an Overlay, or any of its subclasses, contains a table with its border-collapse CSS property set to "collapse" instead of the default value of "separate", the borders of the table will remain visible, when the Overlay is configured to be initially hidden. The table contents will be hidden correctly.

    This is due to an IE bug, reproducible by the basic test case below:

    The simplest workaround if you're not using effects, is to use Overlay's hide() method to setup visibility. This will set the Overlays element's "style.visibility" property, which fixes the bug:

    You can also apply this workaround if you want to use effects by setting the effect up after you hide:

    If initial flicker is a problem with the above solutions, you could set the visibility directly on the Overlay element after rendering:

    However, if possible one of the previous methods should be used since they use the public API as opposed to manipulating the DOM directly.

  • Text input/Textarea caret not displayed in Firefox

    When a Panel's "modal" or "iframe" options are enabled, Gecko-based browsers such as Firefox do not render the flashing caret for text input boxes or text areas contained inside the Panel.

    This is a known problem with Gecko-based browsers related to text input fields being rendered on top of elements with overflow set to "auto" or "scroll", or iframes. More information can be found in the Mozilla bug report for the issue.

    The simplest workaround when using the modal mask, would be to set overflow to "visible" (or "hidden") on the mask, overriding the default value of "auto":

    However, there are side-effects associated with this simple mask workaround and it cannot always be applied.

    The value of "overflow:auto" applied to the mask by default is used to workaround another Mozilla bug and prevents scrollbars in Gecko-based browsers on MacOS from bleeding through the mask. If you intend to support Gecko-based browsers on MacOS and your page has elements with scrollbars, then this workaround cannot be used. Note that it also does not solve the problem if you have the "iframe" option enabled, or other page elements with overflow set to "auto" or "scroll" underneath the Panel.

    A more complex workaround for the bug involves setting "overflow:auto" on the text field (or one of it's containers) and also flipping it's display property (see Mozilla Bug 167801, comment 84). Although more complex, this workaround helps resolve the issue for both the iframe and modal mask use cases, as well any other elements you may have on the page with overflow set to "auto" or "scroll".

    See the following example with this workaround applied: Text Input Cursor Fix.

  • Container inherits text-align values

    The container family, as currently implemented, does not force a default CSS text-align value for it's contents other than a text-align:right for Dialog's footer buttons. By default, text will be aligned based on the text-align value inherited from the container's ancestor(s) in the document.

    A common YUI scenario where you may see this is when YUI Grids is used. Containers rendered to document.body will have text-align evaluate to center, inherited from the YUI Grids rule for the body element.

    If you do need to specify a default text-align value for any particular member of the container family (and it's subclasses), a simple option is to use the default class name, to define your default text-align value:

  • HTML Validator Mozilla Add-on causes NS_BASE_STREAM_CLOSED chrome exception

    The HTML Validator add-on for Mozilla browsers is known to cause a NS_BASE_STREAM_CLOSED chrome exception, when monitorresize is enabled. The exception does not impact container functionality.

    This appears to be a bug in the HTML Validator add-on and it's ability to validate pages with iframes containing data: urls, which are used by container to implement the monitorresize functionality for Gecko browers. The issue has been posted on the bug forum for the add-on.

    Disabling the add-on will fix the problem.

YUI on Mobile: Using Container Family with "A-Grade" Mobile Browsers

About this Section: YUI generally works well with mobile browsers that are based on A-Grade browser foundations. For example, Nokia's N-series phones, including the N95, use a browser based on Webkit — the same foundation shared by Apple's Safari browser, which is found on the iPhone. The fundamental challenges in developing for this emerging class of full, A-Grade-derived browsers on handheld devices are:

  • Screen size: You have a much smaller canvas;
  • Input devices: Mobile devices generally do not have mouse input, and therefore are missing some or all mouse events (like mouseover);
  • Processor power: Mobile devices have slower processors that can more easily be saturated by JavaScript and DOM interactions — and processor usage affects things like battery life in ways that don't have analogues in desktop browsers;
  • Latency: Most mobile devices have a much higher latency on the network than do terrestrially networked PCs; this can make pages with many script, css or other types of external files load much more slowly.

There are other considerations, many of them device/browser specific (for example, current versions of the iPhone's Safari browser do not support Flash). The goal of these sections on YUI User's Guides is to provide you some preliminary insights about how specific components perform on this emerging class of mobile devices. Although we have not done exhaustive testing, and although these browsers are revving quickly and present a moving target, our goal is to provide some early, provisional advice to help you get started as you contemplate how your YUI-based application will render in the mobile world.

More Information:

The Container family of controls has a few limitations when run on the default browsers for the Nokia N95 and Apple iPhone, but a majority of the feature set works correctly.

Below is a list of know issues for the mobile environments tested:

  • Draggable containers are not supported

    Neither the iPhone nor the Nokia N95 were able to generate the events required to support Drag and Drop within the browser, and hence draggable containers are not supported. The same limitation would apply to the resizable container example.

  • Tooltips are not supported on the iPhone

    Due to the absence of consistent mouseover/mouseout events on the iPhone, Tooltips cannot be displayed reliably. It's likely that other touch based devices have similar limitations.

    Tooltips will work on the Nokia N95, since it has a cursor, and it's likely they'd work on other cursor/joystick based devices

  • constraintoviewport and fixedcenter configuration properties are not accurate on the iPhone

    The viewport size for the iPhone (as retrieved via the Dom Collection) is the same as the document size and does not reflect the visible screen region as it normally should. As a result, constraintoviewport or fixedcenter are calculated relative to the document size rather than the actual visible screen size. This is likely to result in the container being displayed outside of the visible screen region.

  • Shadows/Modal Mask appear opaque on the Nokia N95

    The default Webkit browser on the Nokia N95 does not honor CSS opacity values and hence partially opaque areas of the Container, such as the shadow and modal mask, appear solid black (100% opaque).

Design Considerations

Some general design issues to consider when working on mobile device solutions using Container.

  • Latency, Slow Networks

    The Container family allows you to generate Container controls from markup; in other words, the markup is delivered to the page and then transformed by JavaScript into the desired Container widget. When working on high-latency mobile networks, this could lead to the unmodified markup being displayed for a significant period of time before the control is actually rendered/hidden. To account for this, you should avoid using the window load event to construct your control and use one of the earlier page lifecycle events — onDOMReady, onContentReady, or onAvailable; see this example in the Event Utility section for more information about these events.

    Alternatively, you could consider building the control from JavaScript, if progressive enhancement is not a requirement.

  • UI Targets

    The default Sam Skin implementation for the Container family works well for mobile devices also. It provides UI targets, such as close buttons, dialog buttons and title bars, which are large enough or have enough whitespace around them so as to be usable on touch devices such as the iPhone.

    If you do wish to optimize the mobile experience for users, you may consider serving up custom skin CSS based on the mobile browser's user agent string. The YAHOO mobile section has an example of how to parse the user agent string on the client; the same logic can be applied on the server also.

    Some of the UI targets/CSS rules you may want to customize when creating a custom mobile skin for Panel based containers to increase their target areas are:

    • Close Button: .yui-skin-sam .yui-panel .container-close
    • Title Bar/Header: .yui-skin-sam .yui-panel .hd
    • Dialogs Buttons: YUI Button CSS

Support & Community

The YUI Library and related topics are discussed on the on the ydn-javascript mailing list.

In addition, please visit the YUIBlog for updates and articles about the YUI Library written by the library's developers.

Filing Bugs & Feature Requests

The YUI Library's public bug tracking and feature request repositories are located on the YUI SourceForge project site. Before filing new feature requests or bug reports, please review our reporting guidelines.

Cheat Sheets for Container-family Controls:

Dialog & SimpleDialog

Cheat Sheet for the Dialog and SimpleDialog Controls.

Panel

Cheat Sheet for the Panel Control.

Download full set of cheat sheets.

Container Family Examples:

Other YUI Examples That Make Use of the Container Family:

YUI Container on del.icio.us:

Copyright © 2008 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings