Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The `rule` slot allows for customizing markup around each rule component.

The slot receives an object with the shape of the [RuleSlotProps
object](https://github.com/rtucek/vue-query-builder/blob/master/types/index.d.ts#L47).
An exact ruel can be identified based on the `ruleCtrl.ruleIdentifier` for dynamic content.

You'll have to use Vue's [Dynamic
Component](https://vuejs.org/v2/guide/components.html#Dynamic-Components) feature for displaying the
Expand Down
1 change: 1 addition & 0 deletions src/QueryBuilderRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class QueryBuilderRule extends Vue {
return {
ruleComponent: this.component,
ruleData: this.query.value,
ruleIdentifier: this.query.identifier,
updateRuleData: (ruleData: any) => this.ruleUpdate(ruleData),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface GroupCtrlSlotProps {
export interface RuleSlotProps {
ruleComponent: Component | string,
ruleData: any,
ruleIdentifier: string,
updateRuleData: (newData: any) => void,
}

Expand Down
4 changes: 4 additions & 0 deletions tests/components/Component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default class Input extends Vue {
@Prop({
default: null,
}) readonly value!: any;

@Prop({
default: null,
}) readonly identifier!: any;
}
</script>

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/slots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ describe('Testing slot related features', () => {
<component
:is="props.ruleComponent"
:value="props.ruleData"
:identifier="props.ruleIdentifier"
@input="props.updateRuleData"
class="slot-rule"
/>
Expand All @@ -197,6 +198,8 @@ describe('Testing slot related features', () => {
// Verify rule slot is properly rendered
expect(ruleComponent.is(Component)).toBeTruthy();
expect(ruleComponent.vm.$props.value).toBe('A');
expect(rule.vm.$props.query.identifier).toBe('txt');
expect(ruleComponent.vm.$props.identifier).toBe('txt');
ruleComponent.vm.$emit('input', 'a');
expect((rule.emitted('query-update') as any)[0][0]).toStrictEqual({ identifier: 'txt', value: 'a' });

Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ export interface GroupCtrlSlotProps {
export interface RuleSlotProps {
ruleComponent: Component | string,
ruleData: any,
ruleIdentifier: string,
updateRuleData: (newData: any) => void,
}