Dropdown List Cutting Off and Unable to Adjust zIndex in React Native

I have a custom dropdown list component that I’m using to populate employee data based on key presses or typing. It works fine, but the problem is with its UI. The dropdown list gets cut off because of its container’s height. For example, if the container has a height of 200, and my dropdown expands to a height of 500, the rest of the dropdown list is hidden behind the container. I’m not an expert in CSS. I tried using zIndex for the dropdown list and even sought help from ChatGPT, but the overall result was still unsuccessful.

Custom Dropdown Component sample :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> let topVal = props.screen === 'createNotification' ? 25 : 35;
return (
<View style={{flex:1, width:'100%', justifyContent:'center', alignItems:'center',
zIndex:100}}>
<TouchableOpacity onPress={() => {
setShowDropdown(!showDropdown)
props.closeTypeDropDown()
}} style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center', width:'100%', paddingHorizontal:15, }}>
<TextInput
placeholder="Type to search..."
value={query}
onChangeText={handleInputChange}
style={{color:COLORS.black}}
/>
{isLoading ? <ActivityIndicator size="small" color={COLORS.themeOrangeBright} /> : <Icon name="chevron-down" size={20} color='#808080' />}
</TouchableOpacity>
{showDropdown && (
<View onStartShouldSetResponder={() => true} style={[styles.dropdownContainer, {top: Platform.OS === 'android' ? 50 : topVal}]}>
<FlatList
// keyboardShouldPersistTaps={'always'}
persistentScrollbar={true}
style={{ zIndex:10, borderRadius:10 }}
data={suggestions}
keyExtractor={(item) => item}
renderItem={({ item }) => (
<TouchableOpacity key={item.id} style={{flex:1, padding:10}} onPress={() => handleSelectSuggestion(item)}>
<Text style={{color: COLORS.black}}>{item.title}</Text>
</TouchableOpacity>
)}
ListEmptyComponent={renderEmptyContainer}
/>
</View>
)}
</View>);};
const styles = StyleSheet.create({
dropdownContainer: {
position: 'absolute',
left: 0,
right: 0,
backgroundColor: 'white',
zIndex: 10,
maxHeight: 200,
borderColor:'#F0F0F0',
borderWidth:1,
borderBottomLeftRadius:10,
borderBottomRightRadius:10},});
</code>
<code> let topVal = props.screen === 'createNotification' ? 25 : 35; return ( <View style={{flex:1, width:'100%', justifyContent:'center', alignItems:'center', zIndex:100}}> <TouchableOpacity onPress={() => { setShowDropdown(!showDropdown) props.closeTypeDropDown() }} style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center', width:'100%', paddingHorizontal:15, }}> <TextInput placeholder="Type to search..." value={query} onChangeText={handleInputChange} style={{color:COLORS.black}} /> {isLoading ? <ActivityIndicator size="small" color={COLORS.themeOrangeBright} /> : <Icon name="chevron-down" size={20} color='#808080' />} </TouchableOpacity> {showDropdown && ( <View onStartShouldSetResponder={() => true} style={[styles.dropdownContainer, {top: Platform.OS === 'android' ? 50 : topVal}]}> <FlatList // keyboardShouldPersistTaps={'always'} persistentScrollbar={true} style={{ zIndex:10, borderRadius:10 }} data={suggestions} keyExtractor={(item) => item} renderItem={({ item }) => ( <TouchableOpacity key={item.id} style={{flex:1, padding:10}} onPress={() => handleSelectSuggestion(item)}> <Text style={{color: COLORS.black}}>{item.title}</Text> </TouchableOpacity> )} ListEmptyComponent={renderEmptyContainer} /> </View> )} </View>);}; const styles = StyleSheet.create({ dropdownContainer: { position: 'absolute', left: 0, right: 0, backgroundColor: 'white', zIndex: 10, maxHeight: 200, borderColor:'#F0F0F0', borderWidth:1, borderBottomLeftRadius:10, borderBottomRightRadius:10},}); </code>
  let topVal = props.screen === 'createNotification' ? 25 : 35;
  return (
  <View style={{flex:1, width:'100%', justifyContent:'center', alignItems:'center', 
  zIndex:100}}>
  <TouchableOpacity onPress={() => {
    setShowDropdown(!showDropdown)
    props.closeTypeDropDown()
    }} style={{flexDirection:'row', justifyContent:'space-between', alignItems:'center', width:'100%', paddingHorizontal:15, }}>
    <TextInput
        placeholder="Type to search..."
        value={query}
        onChangeText={handleInputChange}
        style={{color:COLORS.black}}
    />
    {isLoading ? <ActivityIndicator size="small" color={COLORS.themeOrangeBright} /> : <Icon name="chevron-down" size={20} color='#808080' />}
  </TouchableOpacity>
  {showDropdown && (
    <View onStartShouldSetResponder={() => true} style={[styles.dropdownContainer, {top: Platform.OS === 'android' ? 50 : topVal}]}>

      <FlatList
        // keyboardShouldPersistTaps={'always'} 
        persistentScrollbar={true}
        style={{ zIndex:10, borderRadius:10 }}
        data={suggestions}
        keyExtractor={(item) => item}
        renderItem={({ item }) => (
          <TouchableOpacity key={item.id} style={{flex:1, padding:10}} onPress={() => handleSelectSuggestion(item)}>
            <Text style={{color: COLORS.black}}>{item.title}</Text>
          </TouchableOpacity>
        )}
        ListEmptyComponent={renderEmptyContainer}
      />
    </View>
  )}
</View>);};

const styles = StyleSheet.create({
dropdownContainer: {
position: 'absolute',    
left: 0,
right: 0,
backgroundColor: 'white',
zIndex: 10,
maxHeight: 200, 
borderColor:'#F0F0F0',
borderWidth:1,
borderBottomLeftRadius:10,
borderBottomRightRadius:10},});

sample where I’m using the above component

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><View style={{ borderBottomWidth: 2, borderBottomColor: '#F0F0F0', marginBottom: 20}}>
<TouchableOpacity onPress={onBlur} activeOpacity={1} style={{ marginBottom: 20 }}>
<MyAppText style={{ width: '28%', fontSize: 16, fontWeight: 400, color: COLORS.black, marginBottom: 5}}>
Employee:
</MyAppText>
<View
style={[{ backgroundColor: '#F0F0F0', borderRadius: 10,zIndex: 1000 },
Platform.OS === 'ios' ? { height: height * 0.05 } : {}
]} >
<DropDownCustom
setSelectedItem={setSelectedItem}
trigger={trigger}
setCloseDropDown={setCloseDropDown}
closeDropDown={closeDropDown}
closeTypeDropDown={closeTypeDropDown}
screen={'createNotification'}
/>
</View>
</TouchableOpacity>
</code>
<code><View style={{ borderBottomWidth: 2, borderBottomColor: '#F0F0F0', marginBottom: 20}}> <TouchableOpacity onPress={onBlur} activeOpacity={1} style={{ marginBottom: 20 }}> <MyAppText style={{ width: '28%', fontSize: 16, fontWeight: 400, color: COLORS.black, marginBottom: 5}}> Employee: </MyAppText> <View style={[{ backgroundColor: '#F0F0F0', borderRadius: 10,zIndex: 1000 }, Platform.OS === 'ios' ? { height: height * 0.05 } : {} ]} > <DropDownCustom setSelectedItem={setSelectedItem} trigger={trigger} setCloseDropDown={setCloseDropDown} closeDropDown={closeDropDown} closeTypeDropDown={closeTypeDropDown} screen={'createNotification'} /> </View> </TouchableOpacity> </code>
<View style={{ borderBottomWidth: 2, borderBottomColor: '#F0F0F0', marginBottom: 20}}>
<TouchableOpacity onPress={onBlur} activeOpacity={1} style={{ marginBottom: 20 }}>
    <MyAppText style={{ width: '28%', fontSize: 16, fontWeight: 400, color: COLORS.black, marginBottom: 5}}>
        Employee:
    </MyAppText>
    <View
        style={[{ backgroundColor: '#F0F0F0', borderRadius: 10,zIndex: 1000 },
            Platform.OS === 'ios' ? { height: height * 0.05 } : {}
        ]} >            
        <DropDownCustom
            setSelectedItem={setSelectedItem}
            trigger={trigger}
            setCloseDropDown={setCloseDropDown}
            closeDropDown={closeDropDown}
            closeTypeDropDown={closeTypeDropDown}
            screen={'createNotification'}
        />
    </View>
</TouchableOpacity>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật