Skip to content

Commit 0faf922

Browse files
author
Matej Lednicky
authored
fix(NOJIRA-123): Set size in pixels by default (#624)
When value with no units (string with numbers only) is provided, set size in pixels by default.
1 parent f0d720c commit 0faf922

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/workflows/visual.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ on:
99
jobs:
1010
visual:
1111
runs-on: ubuntu-latest
12-
# skip for external PRs
13-
if: github.event.pull_request.head.repo.full_name == github.repository
12+
# skip for external PRs, run for push on main branch
13+
if: ${{ !github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository }}
1414
steps:
1515
- name: Check out Git repository
1616
uses: actions/checkout@v2

packages/embed/src/utils/set-element-size.spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setElementSize } from './set-element-size'
1+
import { getValueWithUnits, setElementSize } from './set-element-size'
22

33
describe('set-element-size', () => {
44
describe('#setElementSize', () => {
@@ -18,7 +18,7 @@ describe('set-element-size', () => {
1818

1919
it('should return an element with width and height', () => {
2020
const element = document.createElement('div')
21-
expect(setElementSize(element, { width: 100, height: 100 })).toHaveStyle({
21+
expect(setElementSize(element, { width: 100, height: '100' })).toHaveStyle({
2222
width: '100px',
2323
height: '100px',
2424
})
@@ -37,4 +37,18 @@ describe('set-element-size', () => {
3737
expect(sizedElement).toHaveStyle('height: 50vh')
3838
})
3939
})
40+
41+
describe('#getValueWithUnits', () => {
42+
it('should return size in pixels for number value', () => {
43+
expect(getValueWithUnits(100)).toBe('100px')
44+
})
45+
46+
it('should return size in pixels for string value containing only numbers', () => {
47+
expect(getValueWithUnits('100')).toBe('100px')
48+
})
49+
50+
it('should keep original units when provided in the value', () => {
51+
expect(getValueWithUnits('100vh')).toBe('100vh')
52+
})
53+
})
4054
})

packages/embed/src/utils/set-element-size.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface ElementSize {
44
}
55

66
export const getValueWithUnits = (value: number | string): string => {
7-
if (typeof value === 'string') {
7+
if (typeof value === 'string' && !value.match(/^[0-9]+$/)) {
88
return value
99
} else {
1010
return `${value}px`

0 commit comments

Comments
 (0)