Merge pull request #1199 from anti-the-social/table-width-percent-unit-handling
Table width percent unit handling
This commit is contained in:
@ -38,6 +38,10 @@ export class TableWidthElement extends XmlComponent {
|
|||||||
constructor(name: string, { type = WidthType.AUTO, size }: ITableWidthProperties) {
|
constructor(name: string, { type = WidthType.AUTO, size }: ITableWidthProperties) {
|
||||||
super(name);
|
super(name);
|
||||||
// super("w:tblW");
|
// super("w:tblW");
|
||||||
this.root.push(new TableWidthAttributes({ type: type, size: measurementOrPercentValue(size) }));
|
let tableWidthValue = size;
|
||||||
|
if (type === WidthType.PERCENTAGE && typeof size === "number") {
|
||||||
|
tableWidthValue = `${size}%`;
|
||||||
|
}
|
||||||
|
this.root.push(new TableWidthAttributes({ type: type, size: measurementOrPercentValue(tableWidthValue) }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ describe("Table", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set the table to provided width", () => {
|
it("should set the table to provided 100% width", () => {
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
@ -282,7 +282,42 @@ describe("Table", () => {
|
|||||||
"w:tblW": {
|
"w:tblW": {
|
||||||
_attr: {
|
_attr: {
|
||||||
"w:type": "pct",
|
"w:type": "pct",
|
||||||
"w:w": 100,
|
"w:w": "100%",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BORDERS,
|
||||||
|
{ "w:tblLayout": { _attr: { "w:type": "fixed" } } },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set the table to provided 1000 DXA", () => {
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
width: {
|
||||||
|
size: 1000,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
layout: TableLayoutType.FIXED,
|
||||||
|
});
|
||||||
|
const tree = new Formatter().format(table);
|
||||||
|
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
|
||||||
|
expect(tree["w:tbl"][0]).to.deep.equal({
|
||||||
|
"w:tblPr": [
|
||||||
|
{
|
||||||
|
"w:tblW": {
|
||||||
|
_attr: {
|
||||||
|
"w:type": "dxa",
|
||||||
|
"w:w": 1000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user