Skip to content

Commit 347f80e

Browse files
committed
The priority of pseudo-classes is set. #352
1 parent acae885 commit 347f80e

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

examples/Pseudo.elm

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Pseudo exposing (..)
2+
3+
import Element exposing (..)
4+
import Element.Background as Background
5+
import Element.Font as Font
6+
7+
8+
main =
9+
Element.layout
10+
[ Background.color (rgba 0 0 0 1)
11+
, Font.color (rgba 1 1 1 1)
12+
, Font.italic
13+
, Font.size 32
14+
, Font.family
15+
[ Font.sansSerif ]
16+
]
17+
<|
18+
column [ centerX, centerY ]
19+
[ el
20+
[ mouseOver [ Background.color <| rgb255 255 0 0 ]
21+
, mouseDown [ Background.color <| rgb255 0 0 255 ]
22+
]
23+
<|
24+
text "The following priority of pseudo classes is fixed"
25+
, el
26+
[ mouseDown [ Background.color <| rgb255 0 0 255 ]
27+
, mouseOver [ Background.color <| rgb255 255 0 0 ]
28+
]
29+
<|
30+
text "hover < focused < active"
31+
]

src/Internal/Model.elm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,21 @@ toStyleSheetString options stylesheet =
26222622
in
26232623
case List.foldl combine { topLevel = [], rules = [] } stylesheet of
26242624
{ topLevel, rules } ->
2625-
renderTopLevelValues topLevel ++ String.concat rules
2625+
let
2626+
ruleWeight s =
2627+
if String.contains ":hover" s then
2628+
1
2629+
2630+
else if String.contains ":focus" s then
2631+
2
2632+
2633+
else if String.contains ":active" s then
2634+
3
2635+
2636+
else
2637+
0
2638+
in
2639+
renderTopLevelValues topLevel ++ String.concat (List.sortBy ruleWeight rules)
26262640

26272641

26282642
renderStyle : OptionRecord -> Maybe PseudoClass -> String -> List Property -> List String

0 commit comments

Comments
 (0)