Skip to content

Commit 34b79a0

Browse files
Adding attribute to child element
1 parent e90199a commit 34b79a0

File tree

3 files changed

+77
-67
lines changed

3 files changed

+77
-67
lines changed

package-lock.json

Lines changed: 47 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vuedraggable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ const draggableComponent = {
169169
update("attrs", attrs);
170170

171171
if (this.componentData) {
172-
const { on, props } = this.componentData;
172+
const { on, props, attrs } = this.componentData;
173173
update("on", on);
174174
update("props", props);
175+
Object.assign(attributes.attrs, attrs);
175176
}
176177
return h(this.getTag(), attributes, children);
177178
},

tests/unit/vuedraggable.spec.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ describe("draggable.vue when initialized with list", () => {
232232
on: {
233233
input
234234
},
235+
attrs: {
236+
attribute1: "value1"
237+
},
235238
props: {
236239
prop1: "info",
237240
prop2: true
@@ -254,12 +257,18 @@ describe("draggable.vue when initialized with list", () => {
254257
expect(fakeChild.props("prop1")).toEqual("info");
255258
})
256259

257-
it("pass data to tag child", async () => {
260+
it("pass event listener to tag child", async () => {
258261
const child = wrapper.find(Fake);
259262
const evt = { data: 33 };
260263
child.vm.$emit('input', evt);
261264
expect(input).toHaveBeenCalledWith(evt);
262265
})
266+
267+
it("pass attributes to tag child", async () => {
268+
const child = wrapper.find(Fake);
269+
const attrValue = child.attributes("attribute1");
270+
expect(attrValue).toEqual("value1");
271+
})
263272
});
264273

265274
it("keeps a reference to Sortable instance", () => {
@@ -521,8 +530,8 @@ describe("draggable.vue when initialized with list", () => {
521530
})
522531

523532
describe.each([
524-
[ 1, ["b", "a", "c"]],
525-
[ 3, ["a", "c", "b"]]
533+
[1, ["b", "a", "c"]],
534+
[3, ["a", "c", "b"]]
526535
])
527536
("when update is called with new index being %i",
528537
(index, expectedList) => {
@@ -562,7 +571,7 @@ describe("draggable.vue when initialized with list", () => {
562571

563572
it("sends a change event", async () => {
564573
await Vue.nextTick();
565-
const expectedEvt = { moved: { element: "b", oldIndex: 1, newIndex: index-1 } };
574+
const expectedEvt = { moved: { element: "b", oldIndex: 1, newIndex: index - 1 } };
566575
expect(wrapper.emitted().change).toEqual([[expectedEvt]]);
567576
})
568577
});
@@ -795,23 +804,23 @@ describe("draggable.vue when initialized with list", () => {
795804
["data-valor2", "bd"],
796805
["data-attribute", "efg"]
797806
])(
798-
"renders attribute %s with value %s as html attribute",
807+
"renders attribute %s with value %s as html attribute",
799808
(attribute, value) => {
800-
wrapper = shallowMount(draggable, {
801-
propsData: {
802-
list: []
803-
},
804-
attrs: {
805-
[attribute]: value,
806-
},
807-
slots: {
808-
default: "",
809-
}
809+
wrapper = shallowMount(draggable, {
810+
propsData: {
811+
list: []
812+
},
813+
attrs: {
814+
[attribute]: value,
815+
},
816+
slots: {
817+
default: "",
818+
}
819+
});
820+
const element = wrapper.find(`[${attribute}='${value}']`);
821+
expect(element.is("div")).toBe(true);
822+
expect(element.html()).toEqual(wrapper.html());
810823
});
811-
const element = wrapper.find(`[${attribute}='${value}']`);
812-
expect(element.is("div")).toBe(true);
813-
expect(element.html()).toEqual(wrapper.html());
814-
});
815824
})
816825

817826
describe("draggable.vue when initialized with value", () => {

0 commit comments

Comments
 (0)