StickyHeader Row is hindering the drop down list view - css

I have made my row header, of material UI Table component, sticky using the stickyHeader attribute
<Table stickyHeader className={classes.table}></Table>
there are two drop-downs displayed above this table, these are implemented using the ReactSelect component
const DropDown = props => (
<div className={[props.divClasses, props.error ? 'error-class' : ''].join(' ')}>
<ReactSelect
{...props}
classNamePrefix="normal-select"
disabled={props.disabled ? props.disabled : false}
multi={props.multi}
placeholder={props.placeholder ? props.placeholder : 'Select'}
closeOnSelect={props.closeOnSelect}
clearable={props.clearable}
searchable={props.searchable}
options={props.options ? props.options : []}
value={props.simpleValue ? props.options.filter(
({ value }) => value === props.value) : props.value}
isLoading={props.isLoading}
className={` ${props.className ? props.className : ''}`}
onChange={option => props.onChange(props.property, props.simpleValue ? option?.value : option)}
onBlur={props.onBlur}/>
{props.error && <FormHelperText style={{ color: '#f44336' }}>{props.error}</FormHelperText>}
</div>
);
because of being sticky, the header of the table component is now corrupting the view of the drop downs
currently, I am getting,
the expected behavior is,
kindly help me in this regard.

The reason of this overlapping is because mui table's sticky header's default z-index value is 2 and is greater than react-select menu's default z-index value 1.
So, you need to increase z-index of react-select component's menu property to some value that is greater than 2 like this:
const customStyles = {
menu: (provided, state) => ({
...provided,
zIndex: 3
})
};
<ReactSelect
value={selectedOption}
onChange={setSelectedOption}
options={options}
styles={customStyles}
/>
You can take a look at this sandbox for a live working example of this usage.

Related

react-beautiful-dnd: How can I make a specific droppable column scrollable instead of scrolling the entire context?

The current context looks like this:
There are a lot of items in the last column, and all columns are elongated and you need to scroll the entire webpage down to see the rest of the items in that last column.
What I want to achieve is:
The droppable columns have a maximum length, such that when there are more draggable items in one of it, the column length does not auto grow anymore. But you can scroll within that column downwards to show more draggable items.
Code:
const ProjectBoardLists = ({ ... }) => {
...
return (
<DragDropContext onDragEnd={HandleIssueDrop}>
<Lists>
{Object.values(IssueStatus).map(status => (
<List
currentUserId={currentUserId}
/>
))}
</Lists>
</DragDropContext>
);
};
and List is defined as
const List = ({ ... }) => {
...
return (
<Droppable key={status} droppableId={status} style={{overflow: "scroll"}}>
{provided => (
<List>
<Title>
{`${IssueStatusCopy[status]} `}
<IssuesCount>{formatIssuesCount(allListIssues, filteredListIssues)}</IssuesCount>
</Title>
<Issues
{...provided.droppableProps}
ref={provided.innerRef}
data-testid={`board-list:${status}`}
>
{filteredListIssues.map((issue, index) => (
<Issue key={issue.id} projectUsers={project.users} issue={issue} index={index} />
))}
{provided.placeholder}
</Issues>
</List>
)}
</Droppable>
);
};
The Documentation (https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/droppable.md#scroll-containers) claims that
This library supports dragging within scroll containers
(DOM elements that have overflow: auto; or overflow: scroll;).
The only supported use cases are:
The <Droppable /> can itself be a scroll container with no scrollable parents
The <Droppable /> has one scrollable parent
So I tried to add style={{overflow: "scroll"}} to <Droppable />, but nothing happened.
How exactly can I do it?

CSS to change react MUI select

I need to change react material UI select component UI to like this.
This is the CSS I have entered up to now
const styles = {
width:'250px',
border:'1px solid gray',
borderBottom:'none',
padding:'1rem'
}
This is the react code.
<FormControl styles={styles}>
{/* <InputLabel id='demo-simple-select-label'>Categories</InputLabel> */}
<Select
labelId='demo-simple-select-label'
id='demo-simple-select'
value={age}
onChange={handleChange}
style={styles}
>
<MenuItem value={'All'}>All</MenuItem>
{categories.map((category) => (
<MenuItem value={category} key={category}>
{category}
</MenuItem>
))}
</Select>
</FormControl>
Here I comment on the InputLable component. So now If nothing is selected the bar is empty. I want to display the text "Categories" when nothing is select using CSS. also fine-tune this code to match 100% as the given design.
How do I achieve this using CSS?
This is my full code
https://codesandbox.io/s/material-demo-forked-wcmx1?file=/demo.js:1028-1606
Any help!
Thanks in advance.
from docs : (https://material-ui.com/api/select/)
displayEmpty
If true, a value is displayed even if no items are selected.
In order to display a meaningful value, a function should be passed to the renderValue prop which returns the value to be displayed when no items are selected. You can only use it when the native prop is false (default).
renderValue
Render the selected value. You can only use it when the native prop is false (default).
Signature:
function(value: any) => ReactNode
value: The value provided to the component.
sandbox

Change div's "perceived window width"

I want to make the content of a div respond to its size, much like if
it was an iframe, but I can't use one.
My intent is to make the content adapt as if it was in a real smaller
screen so the user can preview the div content on mobile devices.
The iframe works, but it breaks react's diff algorithm, so I can't change the frame contents using the parent props anymore.
So, I want to be able to resize a div which will make it's contents responde
to it's media queries like if they are on a smaller window.
const Index = ({format}) => {
const classes = useStyles ({format})
// if I use iframe instead of div, the breakpoints works,
// but it breaks a lot of app logic
return <div className={classes.root}>
<ChildrenToPerceiveBreakpoint/>
</div>
}
const useStyles = makeStyles(theme => ({
root: props => ({
overflow: props?.format ? 'auto' : 'visible',
maxWidth: props?.format === 'mobile'
? 'min(414px, 100%)'
: props?.format === 'tablet'
? 'min(768px, 100%)'
: '100%',
maxHeight: props?.format === 'mobile'
? 'min(736px, 100%)'
: props?.format === 'tablet'
? 'min(1024px, 100%)'
: '100%',
margin: '0% auto',
marginTop: props?.format === 'mobile'
&& theme.breakpoints.down('md')
? '5%'
: '0%',
}),
}))
I'm using material-ui and jss for the styling.
Thx!

How to dynamically adjust textarea height with React?

I want to adjust my textarea height dynamically with Refs and pass it to the state but it don't work correctly.
I created a codesandbox to help you to understand what exactly I want.
https://codesandbox.io/s/ol5277rr25
You can solve this by using useRef and useLayoutEffect built-in hooks of react. This approach updates the height of the textarea before any rendering in the browser and therefor avoids any "visual update"/flickering/jumping of the textarea.
import React from "react";
const MIN_TEXTAREA_HEIGHT = 32;
export default function App() {
const textareaRef = React.useRef(null);
const [value, setValue] = React.useState("");
const onChange = (event) => setValue(event.target.value);
React.useLayoutEffect(() => {
// Reset height - important to shrink on delete
textareaRef.current.style.height = "inherit";
// Set height
textareaRef.current.style.height = `${Math.max(
textareaRef.current.scrollHeight,
MIN_TEXTAREA_HEIGHT
)}px`;
}, [value]);
return (
<textarea
onChange={onChange}
ref={textareaRef}
style={{
minHeight: MIN_TEXTAREA_HEIGHT,
resize: "none"
}}
value={value}
/>
);
}
https://codesandbox.io/s/react-textarea-auto-height-s96b2
Here's a simple solution that doesn't involve refs. The textarea is dynamically adusted using some CSS and the rows attribute. I used this myself, recently (example: https://codesandbox.io/embed/q8174ky809).
In your component, grab the textarea, calculate the current number of rows, and add 1:
const textArea = document.querySelector('textarea')
const textRowCount = textArea ? textArea.value.split("\n").length : 0
const rows = textRowCount + 1
return (
<div>
<textarea
rows={rows}
placeholder="Enter text here."
onKeyPress={/* do something that results in rendering */}
... />
</div>
)
And in your CSS:
textarea {
min-height: 26vh; // adjust this as you see fit
height: unset; // so the height of the textarea isn't overruled by something else
}
You can check the repo. Or you can add the package to your project.
https://github.com/andreypopp/react-textarea-autosize
Also if you really willing to learn how the logic working exactly;
https://github.com/andreypopp/react-textarea-autosize/blob/master/src/calculateNodeHeight.js
There is a source code with all calculations together.

How to hide back button of React Native navigator

I have made a login button which will jump to main-ui. I don't want people to see the back button at top-left position of navigator's default style.
It seems that NavigatorIOS has no suitable API to use. Can you give me some idea?
You'll have to use Navigator. I recommend using it in conjunction with React Native Navbar.
With Navbar, you can pass in the right and left button components... Or just make them an empty view, if they shouldn't be visible. The property is leftButton and rightButton.
The navigator example on the React docs should get you started:
<Navigator
initialRoute={{name: 'My First Scene', index: 0}}
renderScene={(route, navigator) =>
<MySceneComponent
name={route.name}
onForward={() => {
var nextIndex = route.index + 1;
navigator.push({
name: 'Scene ' + nextIndex,
index: nextIndex,
});
}}
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
/>
}
/>
Now in the definition of MySceneComponent you would include displaying NavBar:
const MySceneComponent = (props) => (
<View style={{ flex: 1, }}>
<NavigationBar
title={titleConfig}
rightButton={BUTTON_OR_NOT}
{...props} />
{props.children}
</View>
);
Of course you will want to abstract your navigation bits perhaps into a component which displays the navigation bar around it as I have shown above with the display of {children}. You will further want to pass the route and navigation information into Navbar so it can display the page information and make it so that clicking on the back button calls navigator.pop(), which is what I did by passing on props via {...props}.

Resources