Skip to content

Commit 7f9805c

Browse files
committed
Add the *as* property in the CHeader component to use semantic tag
1 parent 7d80cc6 commit 7f9805c

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Diff for: packages/coreui-vue/src/components/header/CHeader.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { defineComponent, h } from 'vue'
33
const CHeader = defineComponent({
44
name: 'CHeader',
55
props: {
6+
/**
7+
* Component used for the root node. Either a string to use a HTML element or a component.
8+
*/
9+
as: {
10+
type: String,
11+
default: 'div',
12+
},
613
/**
714
* Defines optional container wrapping children elements.
815
*
@@ -31,7 +38,7 @@ const CHeader = defineComponent({
3138
setup(props, { slots }) {
3239
return () =>
3340
h(
34-
'div',
41+
props.as,
3542
{ class: ['header', { [`header-${props.position}`]: props.position }] },
3643
props.container
3744
? h(

Diff for: packages/coreui-vue/src/components/header/__tests__/CHeader.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ const customWrapper = mount(Component, {
2020
},
2121
})
2222

23+
const customWrapperTwo = mount(Component, {
24+
propsData: {
25+
as: 'header',
26+
},
27+
slots: {
28+
default: 'Default slot',
29+
},
30+
})
31+
2332
describe(`Loads and display ${ComponentName} component`, () => {
2433
it('has a name', () => {
2534
expect(Component.name).toMatch(ComponentName)
@@ -44,3 +53,13 @@ describe(`Customize ${ComponentName} component`, () => {
4453
expect(customWrapper.find('.container-lg').classes('container-lg')).toBe(true)
4554
})
4655
})
56+
57+
58+
describe(`Customize (number two) ${ComponentName} component`, () => {
59+
it('renders correctly', () => {
60+
expect(customWrapperTwo.html()).toMatchSnapshot()
61+
})
62+
it('tag name is custom', () => {
63+
expect(customWrapperTwo.element.tagName).toBe('HEADER')
64+
})
65+
})

Diff for: packages/docs/api/header/CHeader.api.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import CHeader from '@coreui/vue/src/components/header/CHeader'
88

99
#### Props
1010

11-
| Prop name | Description | Type | Values | Default |
12-
| ------------- | ------------------------------------------------------ | --------------- | ------------------------------------------------------------- | ------- |
13-
| **container** | Defines optional container wrapping children elements. | boolean\|string | `boolean`, `'sm'`, `'md'`, `'lg'`, `'xl'`, `'xxl'`, `'fluid'` | - |
14-
| **position** | Place header in non-static positions. | string | `'fixed'`, `'sticky'` | - |
11+
| Prop name | Description | Type | Values | Default |
12+
| ------------- | --------------------------------------------------------------------------------------- | --------------- | ------------------------------------------------------------- | ------- |
13+
| **as** | Component used for the root node. Either a string to use a HTML element or a component. | string | - | 'div' |
14+
| **container** | Defines optional container wrapping children elements. | boolean\|string | `boolean`, `'sm'`, `'md'`, `'lg'`, `'xl'`, `'xxl'`, `'fluid'` | - |
15+
| **position** | Place header in non-static positions. | string | `'fixed'`, `'sticky'` | - |

0 commit comments

Comments
 (0)