Skip to content

Commit d4faa77

Browse files
committed
Log an error on native if using zIndex without position
Non-static position is required for zIndex to have an effect. This error matches the warning in the browser dev tools
1 parent 0cc30bc commit d4faa77

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/react-strict-dom/src/native/modules/createStrictDOMComponent.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ export function createStrictDOMComponent<T, P: StrictProps>(
115115
}
116116
});
117117
}
118+
119+
if (nativeStyle.zIndex != null && nativeStyle.position === 'static') {
120+
errorMsg(
121+
'"position:static" prevents "zIndex" from having an effect. Try setting "position" to something other than "static".'
122+
);
123+
}
118124
}
119125

120126
if (displayValue === 'flex') {

packages/react-strict-dom/tests/html-test.native.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,40 @@ describe('<html.*>', () => {
138138
});
139139
});
140140

141+
test('zIndex with position:static', () => {
142+
const styles = css.create({
143+
static: {
144+
position: 'static',
145+
zIndex: 1
146+
}
147+
});
148+
act(() => {
149+
create(<html.div style={styles.static} />);
150+
});
151+
expect(console.error).toHaveBeenCalledWith(
152+
expect.stringContaining(
153+
'"position:static" prevents "zIndex" from having an effect.'
154+
)
155+
);
156+
});
157+
158+
test('zIndex with position:relative', () => {
159+
const styles = css.create({
160+
relative: {
161+
position: 'relative',
162+
zIndex: 1
163+
}
164+
});
165+
act(() => {
166+
create(<html.div style={styles.relative} />);
167+
});
168+
expect(console.error).not.toHaveBeenCalledWith(
169+
expect.stringContaining(
170+
'"position:static" prevents "zIndex" from having an effect.'
171+
)
172+
);
173+
});
174+
141175
test('auto-wraps raw strings', () => {
142176
const styles = css.create({
143177
root: {

0 commit comments

Comments
 (0)