Skip to content

CellOptions padding does not override TableOptions padding when set to 0 #124

@jennifer-shehane

Description

@jennifer-shehane

If you try to override padding-left or padding-right TableOptions style with a CellOptions style with 'padding-left': 0 or 'padding-right': 0 there is no effect.

The 0 values in the cell also do not override the default padding in cli-table3.

The padding-left and padding-right set to 0 does work fine in the TableOptions however. The bug is only in overriding the Table options

const Table = require('cli-table3')

let table = new Table({
  'style': {
    'padding-left': 1, // default Table option is padding 1
  },
})

table.push([
  {
    content: 'a',
    'style': {
      'padding-left': 5,  // padding 5 👍 	
    },
  },
  {
    content: 'b',
    'style': {
      'padding-left': 1, // padding 1 👍 	
    },
  },
  {
    content: 'c',
    'style': {
      'padding-left': 0,  // padding 0 :(  no effect 	
    },
  },
  {
    content: 'd',
    'style': {
      'padding-left': -1,  // padding -1 kind of has 0 padding 
						   // but then has to offset with colWidths 2 to work
    },
  },
])

console.log(table.toString())

Resulting table:

Screen Shot 2019-09-13 at 3 36 21 PM

The tests do not cover a 0 case of padding here:

it('if set will override tableOptions.style', function() {

This line is culprit:

targetObj[nameA] = objA[nameA] || objA[nameB] || objB[nameA] || objB[nameB];

When padding-left in the Cell style options is a positive number (2) this is evaluating out as:

obj.paddingLeft = 
  cellStyleObj.paddingLeft ||      // evaluates to undefined
  cellStyleObj[padding-left] ||    // evaluates to 2
  tableStyleObj.paddingLeft ||     // evaluates to undefined
  tableStyleObj.[padding-left]     // evaluates to 1

// paddingLeft = 2 yay!!

When padding-left in the Cell style options is 0 this is evaluating out as:

obj.paddingLeft = 
  cellStyleObj.paddingLeft ||    // evaluates to undefined
  cellStyleObj[padding-left] ||  // evaluates to 0
  tableStyleObj.paddingLeft ||   // evaluates to undefined
  tableStyleObj.[padding-left]   // evaluates to 1

// paddingLeft = 1 oh no!!

I would love to submit a PR, but honestly I have no idea if I will have the time. Hopefully this is helpful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions