Skip to content

Commit

Permalink
feat(#602): Support multi-word prop names
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed Jan 15, 2024
1 parent d6d9a68 commit 30ef996
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/api/define-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { compose, required, matchesPattern, shouldThrow, withMessage } from '@ty
import { standard } from '@tybalt/parser';
import { derive, reactive } from '@tybalt/reactive';

import { toKebabCase } from 'js-convert-case';

import type { Reactive } from '@tybalt/reactive';

import ContextEvent from './context-event';
Expand Down Expand Up @@ -330,7 +332,7 @@ export default ({
*/
#updateProps() {
for (const [key, value] of Object.entries(this.#props)) {
const attributeValue = this.getAttribute(key);
const attributeValue = this.getAttribute(toKebabCase(key));
const usingDefault = attributeValue === null && value.value;
const areDifferent = attributeValue !== value.value;
if (!usingDefault && areDifferent) {
Expand Down
26 changes: 26 additions & 0 deletions packages/core/tst/integration/component-rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,30 @@ describe('component rendering', () => {

expect(actual?.value).toBe(expected);
});

it('passes multi-word props to children correctly', async () => {
const name = 'pass-multi-word-props-to-children';
const childComponentName = 'multi-word-child-component';
const expected = 'expected value';

let actual;
defineComponent({
name: childComponentName,
props: { multiWordProp: {} },
setup({ multiWordProp }) {
actual = multiWordProp;
},
});
const parentComponent = defineComponent({
name,
props: { multiWordProp: {} },
render({ multiWordProp }) {
return html`<${childComponentName} multi-word-prop="${multiWordProp}"></${childComponentName}>`;
},
});

await mount(parentComponent, { attributes: { multiWordProp: expected } });

expect(actual?.value).toBe(expected);
});
});

0 comments on commit 30ef996

Please sign in to comment.