Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support auto as value for positioning props #178

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ exports.parseMeasurement = function parseMeasurement(val) {
return exports.parsePercent(val);
};

exports.parseInheritingMeasurement = function parseInheritingMeasurement(v) {
if (String(v).toLowerCase() === 'auto') {
return 'auto';
}
if (String(v).toLowerCase() === 'inherit') {
return 'inherit';
}
return exports.parseMeasurement(v);
};

exports.parseUrl = function parseUrl(val) {
var type = exports.valueType(val);
if (type === exports.TYPES.NULL_OR_EMPTY_STR) {
Expand Down
2 changes: 1 addition & 1 deletion lib/properties/bottom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var parseMeasurement = require('../parsers').parseMeasurement;
var parseMeasurement = require('../parsers').parseInheritingMeasurement;

module.exports.definition = {
set: function (v) {
Expand Down
2 changes: 1 addition & 1 deletion lib/properties/left.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var parseMeasurement = require('../parsers').parseMeasurement;
var parseMeasurement = require('../parsers').parseInheritingMeasurement;

module.exports.definition = {
set: function (v) {
Expand Down
2 changes: 1 addition & 1 deletion lib/properties/right.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var parseMeasurement = require('../parsers').parseMeasurement;
var parseMeasurement = require('../parsers').parseInheritingMeasurement;

module.exports.definition = {
set: function (v) {
Expand Down
2 changes: 1 addition & 1 deletion lib/properties/top.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var parseMeasurement = require('../parsers').parseMeasurement;
var parseMeasurement = require('../parsers').parseInheritingMeasurement;

module.exports.definition = {
set: function (v) {
Expand Down
9 changes: 9 additions & 0 deletions test/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ describe('CSSStyleDeclaration', () => {
assert.strictEqual(style.cssText, 'top: 0px; left: 0%; right: 5em; bottom: 12pt;');
});

it('top, left, right, bottom properties should accept "auto"', () => {
var style = new CSSStyleDeclaration();
style.cssText = `top: auto; right: auto; bottom: auto; left: auto;`;
assert.strictEqual(style.top, 'auto');
assert.strictEqual(style.right, 'auto');
assert.strictEqual(style.bottom, 'auto');
assert.strictEqual(style.left, 'auto');
});

it('clear and clip properties', () => {
var style = new CSSStyleDeclaration();
style.clear = 'none';
Expand Down