diff --git a/docs/userGuide/components/advanced.md b/docs/userGuide/components/advanced.md index f4fbe22187..7843509881 100644 --- a/docs/userGuide/components/advanced.md +++ b/docs/userGuide/components/advanced.md @@ -90,6 +90,10 @@ Slot name | Default class header
`title`
(deprecated)
| `popover-header` content | `popover-body` +**Dropdown Slot Options:** +Slot name | Default class +--- | --- +header | `dropdown-toggle` ### Inserting custom classes into components diff --git a/docs/userGuide/syntax/dropdowns.mbdf b/docs/userGuide/syntax/dropdowns.mbdf index 46d3f7372f..3d317a49e0 100644 --- a/docs/userGuide/syntax/dropdowns.mbdf +++ b/docs/userGuide/syntax/dropdowns.mbdf @@ -6,7 +6,8 @@ ```html - + +
  • Action
  • Another action
  • Something else here
  • @@ -28,7 +29,7 @@
    - +
  • Action
  • Another action
  • Something else here
  • @@ -102,7 +103,7 @@ Name | Type | Default | Description --- | --- | --- | --- disabled | `Boolean` | `false` | Whether Dropdown can be opened. menu-align-right | `Boolean` | `false` | Whether the dropdown list will be right-aligned. -header
    text
    (deprecated)
    | `String` | `''` | Dropdown button header text. +header
    text
    (deprecated)
    | `String` | `''` | Dropdown button header text. (Supports inline MarkDown syntax) type | `String` | `default` | Supports: `default`, `primary`, `danger`, `info`, `warning`, `success`.
    diff --git a/src/lib/markbind/src/parsers/componentParser.js b/src/lib/markbind/src/parsers/componentParser.js index 51227275ba..982fc2b596 100644 --- a/src/lib/markbind/src/parsers/componentParser.js +++ b/src/lib/markbind/src/parsers/componentParser.js @@ -187,6 +187,33 @@ function _parseBoxAttributes(element) { // TODO warn when light and seamless attributes are both present } +/* + * Dropdowns + */ + +function _parseDropdownAttributes(element) { + const el = element; + const slotChildren = el.children && el.children.filter(child => _.has(child.attribs, 'slot')); + const hasHeaderSlot = slotChildren && slotChildren.some(child => child.attribs.slot === 'header'); + + // If header slot is present, the header attribute has no effect, and we can simply remove it. + if (hasHeaderSlot) { + delete el.attribs.header; + // TODO deprecate text attribute of dropdown + delete el.attribs.text; + return; + } + + // header attribute takes priority over text attribute + if (_.has(element.attribs, 'header')) { + _parseAttributeWithoutOverride(element, 'header', true, '_header'); + delete el.attribs.text; + } else { + // TODO deprecate text attribute of dropdown + _parseAttributeWithoutOverride(element, 'text', true, '_header'); + } +} + /* * API */ @@ -213,6 +240,9 @@ function parseComponents(element, errorHandler) { case 'box': _parseBoxAttributes(element); break; + case 'dropdown': + _parseDropdownAttributes(element); + break; default: break; } diff --git a/test/functional/test_site/expected/testAntiFOUCStyles.html b/test/functional/test_site/expected/testAntiFOUCStyles.html index 860aeb136e..b71b931232 100644 --- a/test/functional/test_site/expected/testAntiFOUCStyles.html +++ b/test/functional/test_site/expected/testAntiFOUCStyles.html @@ -30,7 +30,7 @@
  • One
  • Two
  • - +
  • Dropdown One
  • Dropdown Two
  • @@ -38,7 +38,7 @@

    Test dropdown in body with text and class attributes

    Test One
    - +
  • Dropdown One
  • Dropdown Two
  • diff --git a/test/functional/test_site_algolia_plugin/expected/index.html b/test/functional/test_site_algolia_plugin/expected/index.html index c2a98a008b..795c3ca50a 100644 --- a/test/functional/test_site_algolia_plugin/expected/index.html +++ b/test/functional/test_site_algolia_plugin/expected/index.html @@ -34,7 +34,7 @@

    Test Algolia plugin adds algolia-no-index classes

    Dropdowns should have algolia-no-index class

    Dropdown
    - +
  • One
  • Two
  • diff --git a/test/functional/test_site_convert/expected/contents/topic1.html b/test/functional/test_site_convert/expected/contents/topic1.html index 7dcdd090ce..0cc18b193d 100644 --- a/test/functional/test_site_convert/expected/contents/topic1.html +++ b/test/functional/test_site_convert/expected/contents/topic1.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_convert/expected/contents/topic2.html b/test/functional/test_site_convert/expected/contents/topic2.html index ac8c3af88e..4f240c1728 100644 --- a/test/functional/test_site_convert/expected/contents/topic2.html +++ b/test/functional/test_site_convert/expected/contents/topic2.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_convert/expected/contents/topic3a.html b/test/functional/test_site_convert/expected/contents/topic3a.html index 013d4a687e..1d49beca79 100644 --- a/test/functional/test_site_convert/expected/contents/topic3a.html +++ b/test/functional/test_site_convert/expected/contents/topic3a.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_convert/expected/contents/topic3b.html b/test/functional/test_site_convert/expected/contents/topic3b.html index 58f8ea202d..c4ef4449a8 100644 --- a/test/functional/test_site_convert/expected/contents/topic3b.html +++ b/test/functional/test_site_convert/expected/contents/topic3b.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_templates/test_default/expected/contents/topic1.html b/test/functional/test_site_templates/test_default/expected/contents/topic1.html index d0f9f7b485..51dcb788d1 100644 --- a/test/functional/test_site_templates/test_default/expected/contents/topic1.html +++ b/test/functional/test_site_templates/test_default/expected/contents/topic1.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_templates/test_default/expected/contents/topic2.html b/test/functional/test_site_templates/test_default/expected/contents/topic2.html index ef0e924772..7cf8cbd462 100644 --- a/test/functional/test_site_templates/test_default/expected/contents/topic2.html +++ b/test/functional/test_site_templates/test_default/expected/contents/topic2.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_templates/test_default/expected/contents/topic3a.html b/test/functional/test_site_templates/test_default/expected/contents/topic3a.html index ee117b3302..7ed403f6c9 100644 --- a/test/functional/test_site_templates/test_default/expected/contents/topic3a.html +++ b/test/functional/test_site_templates/test_default/expected/contents/topic3a.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_templates/test_default/expected/contents/topic3b.html b/test/functional/test_site_templates/test_default/expected/contents/topic3b.html index 379c1d657e..522c1e9bc4 100644 --- a/test/functional/test_site_templates/test_default/expected/contents/topic3b.html +++ b/test/functional/test_site_templates/test_default/expected/contents/topic3b.html @@ -27,7 +27,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/functional/test_site_templates/test_default/expected/index.html b/test/functional/test_site_templates/test_default/expected/index.html index 281cc77f97..cbee9a10e7 100644 --- a/test/functional/test_site_templates/test_default/expected/index.html +++ b/test/functional/test_site_templates/test_default/expected/index.html @@ -28,7 +28,7 @@
  • Topic 1
  • Topic 2
  • - +
  • Topic 3a
  • Topic 3b
  • diff --git a/test/unit/parsers/componentParser.test.js b/test/unit/parsers/componentParser.test.js index a302918ecc..cb9026c85d 100644 --- a/test/unit/parsers/componentParser.test.js +++ b/test/unit/parsers/componentParser.test.js @@ -97,3 +97,23 @@ test('postParseComponent assigns the correct header id to panels', () => { testData.POST_PARSE_PANEL_ID_ASSIGNED_USING_HEADER_SLOT_EXPECTED, true); }); + +test('parseComponent parses dropdown header attribute and inserts into DOM as _header slot correctly', () => { + parseAndVerifyTemplate(testData.PARSE_DROPDOWN_HEADER, + testData.PARSE_DROPDOWN_HEADER_EXPECTED); +}); + +test('parseComponent parses dropdown text attribute and inserts into DOM as _header slot correctly', () => { + parseAndVerifyTemplate(testData.PARSE_DROPDOWN_TEXT_ATTR, + testData.PARSE_DROPDOWN_TEXT_ATTR_EXPECTED); +}); + +test('parseComponent parses dropdown with header taking priority over text attribute', () => { + parseAndVerifyTemplate(testData.PARSE_DROPDOWN_HEADER_SHADOWS_TEXT, + testData.PARSE_DROPDOWN_HEADER_SHADOWS_TEXT_EXPECTED); +}); + +test('parseComponent parses dropdown with header slot taking priority over header attribute', () => { + parseAndVerifyTemplate(testData.PARSE_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY, + testData.PARSE_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_EXPECTED); +}); diff --git a/test/unit/utils/componentParserData.js b/test/unit/utils/componentParserData.js index ea905b81d1..3b73b88997 100644 --- a/test/unit/utils/componentParserData.js +++ b/test/unit/utils/componentParserData.js @@ -279,4 +279,62 @@ module.exports.PARSE_BOX_HEADING_EXPECTED = ` `; +/** + * Dropdowns + */ + +module.exports.PARSE_DROPDOWN_HEADER = ` + + Header attribute should be inserted as internal _header slot and deleted. + +`; + +module.exports.PARSE_DROPDOWN_HEADER_EXPECTED = ` + + Header attribute should be inserted as internal _header slot and deleted. + +`; + +// TODO deprecate text attribute of dropdown +module.exports.PARSE_DROPDOWN_TEXT_ATTR = ` + + Text attribute should be inserted as internal _header slot and deleted. + +`; + +// TODO deprecate text attribute of dropdown +module.exports.PARSE_DROPDOWN_TEXT_ATTR_EXPECTED = ` + + Text attribute should be inserted as internal _header slot and deleted. + +`; + +// TODO deprecate text attribute of dropdown +module.exports.PARSE_DROPDOWN_HEADER_SHADOWS_TEXT = ` + + Header attribute should be inserted as internal _header slot and deleted. Text attribute should be ignored. + +`; + +// TODO deprecate text attribute of dropdown +module.exports.PARSE_DROPDOWN_HEADER_SHADOWS_TEXT_EXPECTED = ` + + Header attribute should be inserted as internal _header slot and deleted. Text attribute should be ignored. + +`; + +module.exports.PARSE_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY = ` + + slot text + Header attribute should be ignored and deleted while header slot is reserved. + +`; + +module.exports.PARSE_DROPDOWN_HEADER_SLOT_TAKES_PRIORITY_EXPECTED = ` + + slot text + Header attribute should be ignored and deleted while header slot is reserved. + +`; + /* eslint-enable max-len */