chenzhaoyang
2025-12-17 063da0bf961e1d35e25dc107f883f7492f4c5a7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* Position-try fallback definitions for anchor positioning */
/* These use implicit anchor references via position-anchor set in JS */
@position-try --dropdown-bottom-left {
  bottom: auto;
  top: anchor(bottom);
  left: anchor(left);
  right: auto;
}
 
@position-try --dropdown-bottom-right {
  bottom: auto;
  top: anchor(bottom);
  right: anchor(right);
  left: auto;
}
 
@position-try --dropdown-bottom-center {
  bottom: auto;
  top: anchor(bottom);
  left: anchor(center);
  right: auto;
  translate: -50% 0;
}
 
@position-try --dropdown-top-left {
  top: auto;
  bottom: anchor(top);
  left: anchor(left);
  right: auto;
}
 
@position-try --dropdown-top-right {
  top: auto;
  bottom: anchor(top);
  right: anchor(right);
  left: auto;
}
 
@position-try --dropdown-top-center {
  top: auto;
  bottom: anchor(top);
  left: anchor(center);
  right: auto;
  translate: -50% 0;
}
 
.dropdown {
  --menu-animation-duration: 0.15s;
  --menu-animation-curve: cubic-bezier(0.21, 1.04, 0.68, 1);
  --menu-animation-start: -10px;
 
  /* Default positioning for fallback (no anchor support) */
  position: absolute;
  top: calc(100% + 1px);
  z-index: 500;
 
  /* Hidden by default - will be shown with animation classes */
  display: none;
  box-sizing: border-box;
  background-color: var(--color-neutral-background);
  box-shadow: 0 5px 20px rgb(var(--color-neutral-shadow-raw) / calc(20% * var(--shadow-intensity)));
  will-change: transform, opacity;
  border-radius: var(--corner-radius-small, 4px);
 
  /* Prevent dropdown from causing page overflow */
  max-width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
 
  /* Use flex column to allow inner scrollable content */
  flex-direction: column;
 
  /* Modern anchor positioning for supported browsers */
  @supports (anchor-name: --test) {
    position: fixed;
 
    /* position-anchor is set dynamically via JavaScript for each dropdown instance */
    /* Default position - anchor() uses the position-anchor value when no name specified */
    top: anchor(bottom);
    left: anchor(left);
    bottom: auto;
    right: auto;
 
    /* Automatic fallback positioning when overflowing */
    position-try-fallbacks:
      --dropdown-bottom-right,
      --dropdown-bottom-center,
      --dropdown-top-left,
      --dropdown-top-right,
      --dropdown-top-center,
      flip-block,
      flip-inline;
 
    /* Only show when anchor is visible */
    position-visibility: anchors-visible;
  }
 
  /* Width syncing with trigger using anchor-size() for anchor positioning */
  &_sync-width {
    @supports (width: anchor-size(width)) {
      /* Use anchor-size() to automatically match trigger width */
      width: anchor-size(width);
      min-width: anchor-size(width);
    }
  }
 
  /* Height constraint using available space calculation of the viewport performed in JS */
  &_constrain-height {
    overflow-y: auto;
  }
 
  &_align {
    &_left {
      left: -20px;
 
      @supports (anchor-name: --test) {
        left: anchor(left);
      }
    }
 
    &_right {
      right: -20px;
 
      @supports (anchor-name: --test) {
        right: anchor(right);
      }
    }
  }
 
  &__trigger {
    position: relative;
 
    /* Set as anchor for modern browsers */
    @supports (anchor-name: --test) {
      anchor-name: --dropdown-trigger;
    }
  }
 
  &.before-appear,
  &.before-disappear {
    transition-property: opacity, transform;
    transition-duration: var(--menu-animation-duration);
    transition-timing-function: var(--menu-animation-curve);
  }
 
  /* Mount state - keeps element in DOM for ref/anchor initialization but invisible */
  &.mounted {
    display: flex;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate3d(0, var(--menu-animation-start), 0);
  }
 
  &.before-appear {
    opacity: 0;
    display: flex;
    transform: translate3d(0, var(--menu-animation-start), 0);
  }
 
  &.appear {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
 
  &.visible {
    opacity: 1;
    display: flex;
  }
 
  &.before-disappear {
    opacity: 1;
    display: flex;
    transform: translate3d(0, 0, 0);
  }
 
  &.disappear {
    opacity: 0;
    visibility: hidden;
    transform: translate3d(0, var(--menu-animation-start), 0);
  }
}