Basically I need to show and Hide the div , Up and Down Arrow Icons should change accordingly. As of Now only UP arrow Icon is working and displaying the div , but when i try to hide the div, it is not working....I did like this and its not working , What wrong in my code? Can Anyone help me in this?
Here is my Code
const [expand, setExpand] = useState(false);
<div onClick={() => setExpand(true)}>
Accordion
<i className={`fas fa-chevron-up ${!expand ? 'fas fa-chevron-down' : ''}`}></i>
</div>
{expand && <div className="Accordion-Section"></div>}
You can set the className like this
<div onClick={() => setExpand(!expand)}>
Accordion
<i className={`fas ${expand ? 'fa-chevron-up' : 'fa-chevron-down'}`} />
</div>
{expand && <div className="Accordion-Section"></div>}
The click handler is setting the state true everytime.
You should change it to <div onClick={() => setExpand(!expand)}>.
you should change "i" tag to this:
<i className={${!expand ? "fas fa-chevron-down" : "fas fa-chevron-up"}}>
Related
I have two separate button like grid and list button:
<button
onClick={() => setClassName('jsGridView')}
title="Grid View"
>
<IoGrid className="active" size="25"/>
</button>
<button
onClick={() => setClassName('jsListView')}
title="List View"
>
<BiAlignLeft size="25"/>
</button>
const [cName, setClassName] = useState('jsGridView');
So when i click Grid view button it will show this component:
<GridCard className={cName}/>
and when i click list view button it will show
<ListCard className={cName}/>
with this mentioned className..
class is changed button but show hide component is not working.
You can display different components depending on the value of cName.
<div className="row mt-4 book-div">
<div className={cName}>
{ cName === 'jsGridView' ? <BooksGridCard/> : <BooksListCard/> }
</div>
</div>
I can see its changing to completed but the css isnt working anyone can help me please. {completed: true, id: 1288.4902006789644, text:...}
this is the code
<div className="todo">
<li className={'todo-item $ {todo.completed ? "completed" : ""}'}>
{text}
</li>
<button onClick={completehandler}>
<FontAwesomeIcon icon={faCheck} />
</button>
<button onClick={deletehandler}>
<FontAwesomeIcon icon={faTrashCan} />
</button>
</div>
this is the CSS
.completed{
text-decoration: line-through;
}
You are not using backtick , you should change ' with backtick ` and you should remove space between $ and {
i am trying to hide a div when it is in mobile view i am using a ternory operator and i am getting error i cannot compltely hide the div becase it already has a ternory operator inside it how can i achive this
{this.state.hidediv?
(<div className="livechat">): (<div className="livechat2">)
} //error here
{this.state.hidecaht ? (
<>
<a
href="#"
className="close"
onClick={() => this.hidechat(true)}
></a>
<Livechat id={this.state.liveid} />
</>
) : null}
</div>
livechat2 has css display:none so it wont show up
img
The issue is that you give an unclosed tag, try this:
<div className={this.state.hidediv ? "livechat" : "livechat2"}>
{this.state.hidecaht &&
<>
<a
href="#"
className="close"
onClick={() => this.hidechat(true)}
></a>
<Livechat id={this.state.liveid} />
</>
}
</div>
I have list of dropdown options which user can select.
optinos in dropdown are made with tag: < a href>:
<a onClick={() => handleSelect(filter)} role="button">
{filter.name}
</a>
Problem is cus I must add tabIndex="0" or -1, to fix error from Eslint.
But When I add tabIndex=0, my button does not work anymore.
Is there are any other way to fix this error?
This is how looks dropdown component:
<ul name="filters" className="dropdown">
{filterOptions.map((filter) => (
<li
key={filter.id}
defaultChecked={filter.name}
name={filter.name}
className={`option option-${filter.selected ? 'selected' : 'unselected'}`}
>
<span className={`option-${filter.selected ? 'checked-box' : 'unchecked-box'} `} />
<a onClick={() => handleSelect(filter)} role="button">
{filter.name}
</a>
</li>
))}
</ul>
Buttons are interactive controls and thus focusable. If the button
role is added to an element that is not focusable by itself (such as
<span>, <div> or <p>) then, the tabindex attribute has to be used to
make the button focusable.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role#Accessibility_concerns
The HTML attribute tabindex corresponds to the attribute tabIndex in
React.
https://reactjs.org/docs/dom-elements.html
So I think #S.. answer is correct:
<a
onClick={() => handleSelect(filter)}
role="button"
tabIndex={0}
>
{filter.name}
</a>
Add a tabindex:
<a onClick={() => handleSelect(filter)} role="button" tabIndex={i}>
{filter.name}
</a>
after first adding an iterator to your map: (filter, i)
I have a custom toggle dropdown:
import React from 'react';
import 'react-datepicker/dist/react-datepicker.css';
const DateRange = props => (
<div className="dropdown artesianDropdownContanier">
<div className="btn-group width100">
<button type="button" className="btn dropdown-width">{props.selected}</button>
<button type="button" className="btn dropdown-toggle dropdown-toggle-split artesianDropdownToggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span className="sr-only">Toggle Dropdown</span>
</button>
<div className="dropdown-menu artesianDropdown">
{props.dropDownValues.map(val => (
<span
key={val}
value={val}
className={`dropdown-item ${props.dropdownItemClass}`}
onClick={() => props.onClick(val)}
aria-hidden="true"
>
{val}
</span>
))
}
</div>
</div>
</div>
);
export default DateRange;
Wich looks like this on the page:
When I go to resize the webpage the arrow portion of the component spills out of its bootstrap container:
If I set display on the arrow to "none" you can see that the dropdown button itself with the text is resizing perfectly. It seems to be the dropdown arrow portion which is giving me trouble.
Any ideas on how to keep this guy firmly in his parent container?
Thanks!
Try adding this style to the component containing {props.selected} :
<button
type="button"
className="btn dropdown-width"
style={{
textOverflow: 'ellipsis',
overflow: 'hidden'
}}
>
{props.selected}
</button>
This should replace the end of the {props.selected} text by 3 dots and let the place to the dropdown button. (some adjustments may be needed depending on your dropdown-width class)