diff --git a/packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js b/packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js index 2e2dca42..eff82a1b 100644 --- a/packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js +++ b/packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js @@ -114,12 +114,13 @@ export function createStrictDOMComponent( ); } }); - } - - if (nativeStyle.zIndex != null && nativeStyle.position === 'static') { - errorMsg( - '"position:static" prevents "zIndex" from having an effect. Try setting "position" to something other than "static".' - ); + // Error message if the element is not a flex child but tries to use + // zIndex without non-static position + if (nativeStyle.zIndex != null && nativeStyle.position === 'static') { + errorMsg( + '"position:static" prevents "zIndex" from having an effect. Try setting "position" to something other than "static".' + ); + } } } diff --git a/packages/react-strict-dom/tests/html-test.native.js b/packages/react-strict-dom/tests/html-test.native.js index 92b3e453..dc4f7b89 100644 --- a/packages/react-strict-dom/tests/html-test.native.js +++ b/packages/react-strict-dom/tests/html-test.native.js @@ -138,38 +138,64 @@ describe('', () => { }); }); - test('zIndex with position:static', () => { - const styles = css.create({ - static: { - position: 'static', - zIndex: 1 - } - }); - act(() => { - create(); + describe('zIndex', () => { + test('with position:static', () => { + const styles = css.create({ + static: { + position: 'static', + zIndex: 1 + } + }); + act(() => { + create(); + }); + expect(console.error).toHaveBeenCalledWith( + expect.stringContaining( + '"position:static" prevents "zIndex" from having an effect.' + ) + ); }); - expect(console.error).toHaveBeenCalledWith( - expect.stringContaining( - '"position:static" prevents "zIndex" from having an effect.' - ) - ); - }); - test('zIndex with position:relative', () => { - const styles = css.create({ - relative: { - position: 'relative', - zIndex: 1 - } + test('with position:static flex child', () => { + const styles = css.create({ + flex: { + display: 'flex' + }, + static: { + position: 'static', + zIndex: 1 + } + }); + act(() => { + create( + + + + ); + }); + expect(console.error).not.toHaveBeenCalledWith( + expect.stringContaining( + '"position:static" prevents "zIndex" from having an effect.' + ) + ); }); - act(() => { - create(); + + test('with position:relative', () => { + const styles = css.create({ + relative: { + position: 'relative', + zIndex: 1 + } + }); + act(() => { + create(); + }); + expect(console.error).not.toHaveBeenCalledWith( + expect.stringContaining( + '"position:static" prevents "zIndex" from having an effect.' + ) + ); }); - expect(console.error).not.toHaveBeenCalledWith( - expect.stringContaining( - '"position:static" prevents "zIndex" from having an effect.' - ) - ); }); test('auto-wraps raw strings', () => {