Skip to content

Commit

Permalink
Treat max-height: 0 as display: none.
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglerchris committed Mar 3, 2024
1 parent 4b04adb commit 75cf9d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ fn styles_from_properties(decls: &DeclarationBlock<'_>) -> Vec<Style> {
}
styles.push(Style::BgColour(color.clone()));
}
Property::MaxHeight(height) => {
use lightningcss::properties::size::MaxSize::*;
use lightningcss::values::percentage::DimensionPercentage::*;
dbg!(&height);
match height {
LengthPercentage(Dimension(dim)) => {
// Treat max-height: 0 the same as display: none.
if Some(0.0) == dim.to_px() {
styles.push(Style::DisplayNone);
}
}
_ => (),
}
}
Property::Display(disp) => {
if let display::Display::Keyword(DisplayKeyword::None) = disp {
styles.push(Style::DisplayNone);
Expand Down
12 changes: 12 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,4 +2327,16 @@ text
"H\ne\nl\nl\no\n*<W></W>\n<W>t</W>\n<W>h</W>\n<W>e</W>\n<W>r</W>\n<W>e</W>\n*\nb\no\no\n",
1);
}

#[test]
fn test_height_0() {
test_html_css(
br#"
<div style="max-height: 0">This should be hidden</div>
<p>Hello</p>"#,
r#"Hello
"#,
20,
);
}
}

0 comments on commit 75cf9d0

Please sign in to comment.