Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(5338): VNode props getter for Accordion, Stepper and TabView #5546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/lib/accordion/Accordion.vue
Expand Up @@ -57,7 +57,7 @@
import ChevronDownIcon from 'primevue/icons/chevrondown';
import ChevronRightIcon from 'primevue/icons/chevronright';
import Ripple from 'primevue/ripple';
import { DomHandler, UniqueComponentId } from 'primevue/utils';
import { DomHandler, UniqueComponentId, ObjectUtils } from 'primevue/utils';
import { mergeProps } from 'vue';
import BaseAccordion from './BaseAccordion.vue';

Expand Down Expand Up @@ -91,7 +91,7 @@ export default {
return this.multiple ? this.d_activeIndex && this.d_activeIndex.includes(index) : this.d_activeIndex === index;
},
getTabProp(tab, name) {
return tab.props ? tab.props[name] : undefined;
return ObjectUtils.getVNodeProp(tab, name);
},
getKey(tab, index) {
return this.getTabProp(tab, 'header') || index;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/stepper/Stepper.vue
Expand Up @@ -135,7 +135,7 @@
</template>

<script>
import { UniqueComponentId } from 'primevue/utils';
import { UniqueComponentId, ObjectUtils } from 'primevue/utils';
import { mergeProps } from 'vue';
import BaseStepper from './BaseStepper.vue';
import StepperContent from './StepperContent.vue';
Expand Down Expand Up @@ -172,7 +172,7 @@ export default {
return this.d_activeStep === index;
},
getStepProp(step, name) {
return step.props ? step.props[name] : undefined;
return ObjectUtils.getVNodeProp(step, name);
},
getStepKey(step, index) {
return this.getStepProp(step, 'header') || index;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/tabview/TabView.vue
Expand Up @@ -95,7 +95,7 @@
import ChevronLeftIcon from 'primevue/icons/chevronleft';
import ChevronRightIcon from 'primevue/icons/chevronright';
import Ripple from 'primevue/ripple';
import { DomHandler, UniqueComponentId } from 'primevue/utils';
import { DomHandler, UniqueComponentId, ObjectUtils } from 'primevue/utils';
import { mergeProps } from 'vue';
import BaseTabView from './BaseTabView.vue';

Expand Down Expand Up @@ -141,7 +141,7 @@ export default {
return this.d_activeIndex === index;
},
getTabProp(tab, name) {
return tab.props ? tab.props[name] : undefined;
return ObjectUtils.getVNodeProp(tab, name);
},
getKey(tab, index) {
return this.getTabProp(tab, 'header') || index;
Expand Down
28 changes: 24 additions & 4 deletions components/lib/utils/ObjectUtils.js
Expand Up @@ -202,15 +202,35 @@ export default {
return str;
},

getVNodeProp(vnode, prop) {
/**
* VNode already "prepared" unit and props don't resolves to camelCase
* Try to find camelCase and after try with kebab-case
*/
getVNodeProp(vnode, camelCaseProp) {
if (vnode) {
let props = vnode.props;

if (props) {
let kebabProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
let propName = Object.prototype.hasOwnProperty.call(props, kebabProp) ? kebabProp : prop;
let foundPropName;

if (Object.prototype.hasOwnProperty.call(props, camelCaseProp)) {
foundPropName = camelCaseProp;
} else {
let kebabProp = this.toKebabCase(camelCaseProp);

return vnode.type.extends.props[prop].type === Boolean && props[propName] === '' ? true : props[propName];
if (Object.prototype.hasOwnProperty.call(props, kebabProp)) {
foundPropName = kebabProp;
}
}

if (foundPropName) {
// vnode.type.extends is a component and it always have camelCase props (due to Vue compile)
if (props[foundPropName] === '' && vnode.type.extends.props[camelCaseProp]?.type === Boolean) {
return true;
}

return props[foundPropName];
}
}
}

Expand Down