Beispiel #1
0
        protected override void OnStart(System.IO.TextWriter writer)
        {
            // Add the outer group
            _buttonGroup = GetHelper().ButtonGroup().Component;
            if (Dropup)
            {
                _buttonGroup.AddCss(Css.Dropup);
            }
            _buttonGroup.Start(writer);

            // Add the action button if split and copy over button CSS classes
            // Also move the icon to the button (if one is present)
            // But only create the split if we actually have some text to put in it
            if (Split && !string.IsNullOrWhiteSpace(TextContent))
            {
                Button button = GetHelper().Button(TextContent).Component;
                MoveIcons(button);
                TextContent = null;
                foreach (string cssClass in CssClasses)
                {
                    button.CssClasses.Add(cssClass);
                }
                button.MergeAttributes(Attributes.Dictionary);
                Attributes.Dictionary.Clear();
                button.StartAndFinish(writer);
            }

            // Create the dropdown button, copy over CSS, add the text and caret, then render
            Button dropdown = GetHelper().Button(buttonType: ButtonType.Button).Component;

            MoveIcons(dropdown);
            dropdown.AddCss(Css.Btn, Css.BtnDefault, Css.DropdownToggle);
            dropdown.MergeAttribute("data-toggle", "dropdown");
            foreach (string cssClass in CssClasses)
            {
                dropdown.CssClasses.Add(cssClass);
            }
            dropdown.MergeAttributes(Attributes.Dictionary);
            Attributes.Dictionary.Clear();
            CssClasses.Clear();
            if (!string.IsNullOrWhiteSpace(TextContent))
            {
                dropdown.AddChild(GetHelper().Content(TextContent + " "));
            }
            else
            {
                Element element = GetHelper().Element("span").AddCss(Css.SrOnly).Component;
                element.AddChild(GetHelper().Content("Toggle Dropdown"));
                dropdown.AddChild(element);
            }
            dropdown.AddChild(GetHelper().Caret());
            TextContent = null;
            dropdown.StartAndFinish(writer);

            // Add CSS and attributes after we've copied all the user-specified stuff to the buttons
            MergeAttribute("role", "menu");
            AddCss(Css.DropdownMenu);

            base.OnStart(writer);
        }