I have a div with a list of elements created on the render method of a component. The style of the container has overflow: scroll however the scroll doesn't show anything else than the initially visible items. I wonder if this behaviour is expected in react and how to fix it.
<div style={{ margin: 15, marginLeft: 35 }}>
<div style={{ display: 'flex', flexDirection: 'row' }}>
<div style={{ marginRight: 10 }}>
Lorem Ipsum
</div>
<div style={{ display: 'block', maxWidth: 300, marginLeft: 20, overflow: 'scroll' }}>
<div> Item visible </div>
<div> Item visible </div>
<div> Item visible </div>
<div> Item visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
<div> Item NOT visible </div>
</div>
</div>
</div>
Instead of using overflow: 'scroll' set overflow: 'auto', event if you set the height of the parent proper scroll bar will come.
Check this example:
class App extends React.Component{
render(){
return(<div style={{ margin: 15, marginLeft: 35 }}>
<div style={{ display: 'flex', flexDirection: 'row' }}>
<div style={{ marginRight: 10 }}>
Lorem Ipsum
</div>
<div style={{overflow: 'auto', height: 'inherit', display: 'block', maxWidth: 300, marginLeft: 20,}}>
<div> Item visible</div>
<div> Item visible</div>
<div> Item visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
<div> Item NOT visible</div>
</div>
</div>
</div>
)
}
}
ReactDOM.render(<App/>,document.getElementById('app'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id='app'/>
Related
I want to develop image gallery. I want to present each image and its description under it and when I click on an image or text or white space got "modal"
I wrote this for an element in gallery
<div class="m-4 img99">
<a href="#ml">
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" class="simg " alt="..." data-toggle="modal" data-target="#ml">
<div class="">
<h5 class="">test</h5>
<p>test</p>
</div>
</a>
</div>
The modal part is
<div class="modal fade" id="ml">
<div class="modal-dialog modal-dialog-centered modal-xl ">
<div class="modal-content">
<!-- Modal Header -->
<!-- Modal body -->
<div class="modal-body ">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 ">
<p>
test
</p>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
and CSS part
.simg {
width: auto;
height: 60px;
}
.img99 {
margin-right: auto !important;
margin-left: auto !important;
width: max-content;
height: max-content;
border: 1px solid rgba(0, 0, 0, 0.15);
}
My problem is when I click on a text or white space the model didn't work. "when I click on image :the model work normally"
https://codepen.io/ahof920/pen/MWYGRYp?editors=1100
What is the problem?
Replace your HTML with this:
Reason why its not working :
Modal are triggered by following tag's in bootstrap data-toggle="modal" data-target="#ml" and you added those inside <img> tag that's the reason modal is opened when clicked on image. So add data-toggle="modal" data-target="#ml" to <a>.
.simg {
width: auto;
height: 60px;
}
.img99 {
margin-right: auto !important;
margin-left: auto !important;
width: max-content;
height: max-content;
border: 1px solid rgba(0, 0, 0, 0.15);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<div class="shadow2 m-4 img99">
<a href="#ml" data-toggle="modal" data-target="#ml">
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" class="simg " alt="...">
<div class="">
<h5 class="">test</h5>
<p>test</p>
</div>
</a>
</div>
<div class="modal fade" id="ml">
<div class="modal-dialog modal-dialog-centered modal-xl ">
<div class="modal-content">
<!-- Modal Header -->
<!-- Modal body -->
<div class="modal-body ">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 ">
<p>
test
</p>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
I want to change li class when el-radio is clicked become active class list, and when the active background class list is blue.
here is my code:
ul class="list-class">
<li v-for="(item, index) in dataList" :key="index">
<div class="row">
<div class="col-md-1">
<el-radio v-model="radio" :label="item.id">
<span></span>
</el-radio>
</div>
<div class="col-md-11">
{{ item.name }}
</div>
</div>
</li>
</ul>
and here my fiddle: https://jsfiddle.net/dede402/38mn5y9q/
add :class="{'active':radio===item.id}" to the v-for iterator
<template>
<ul class="list-class">
<li v-for="(item, index) in dataList" :key="index" :class="{'active':radio===item.id}">
<div class="row">
<div class="col-md-1">
<el-radio v-model="radio" :label="item.id">
<span></span>
</el-radio>
</div>
<div class="col-md-11">
{{ item.name }}
</div>
</div>
</li>
</ul>
<pre class="pre-item">radio = {{ radio }}</pre>
</template>
fiddle: https://jsfiddle.net/38mn5y9q/4/
I am using Bootstrap's Modal class to have a modal appear after clicking a button. The code works - the button is clicked and the modal appears, however, the whole screen is grayed-out and the modal cannot be clicked. I cannot close the modal since it is "in" the gray background. You can see in the image below:
Here is the code:
<!-- Modal -->
<div id="myModal" class="modal fade" style="z-index: 9999;" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<section id="profileMain">
<form class="formoid-solid-dark"
style="background-color: #FFFFFF; font-size: 14px; font-family: 'Trebuchet MS','Roboto', Arial, Helvetica, sans-serif; color: #34495E; max-width: 800px; min-width: 150px"
method="post" action="">
<div class="title">
<h2>Intake Request</h2>
</div>
<div id="mainFormTabs" class="container">
<ul class="nav nav-pills">
<li><a data-toggle="tab" href="#tabCM">Comments</a></li>
</ul>
<div class="container" style="border:1px solid #34495E; border-radius: 0px 4px 4px 4px;">
<div class="tab-content clearfix" style="padding: 10px;">
<div id="tabCM" class="tab-pane fade">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
</div>
</div>
</div>
</div>
</form>
</section>
I have tried adjusting the z-index for the modal, I have moved the modal div outside the body, at the top, and at the bottom of the html form, but none of these worked.
I appreciate any ideas on how to fix this.
You probably fixed it, but there may somebody who can't. The solution to this problem is;
$("#myModal").prependTo("body");
I went back and moved the modal div outside the body tag and it is now working.
</body>
<!-- Modal -->
<div id="myModal" class="modal fade" style="z-index: 9999;" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</html>
I guess than you ready solve, but, just for documentation purpose, you can add this to the css and will help
.modal-backdrop {
display: none;
z-index: 1040 !important;
}
.modal-content {
margin: 2px auto;
z-index: 1100 !important;
}
If you cant place modal section outside body, you can try use this:
<script>
$(document).ready(function () {
$("#modalBtnClick").on("click", function () {
$('#myModal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
});
</script>
and don't forget add id attribute to your button:
<button id="modalBtnClick" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
I had this problem and fixed by giving modal z-index css property :
style="z-index: 999999999;"
as previous solutions didn't work for me
routes.js
Router.route('/', function () {
this.render('Home');
});
Router.route('wall', function () {
this.render('Wall');
});
landing.html
<template name="home">
...
</template>
drawingApp.html
<body>
{{> wall}}
</body>
<template name="wall">
...
{{> canvas}}
...
</template>
<template name="canvas">
...
</template>
drawingApp.js
...
Template.wall.events({
...
If I include <body> {{> wall}} </body>, the landing page renders below the app. If I delete <body> {{> wall}} </body>, landing page renders properly, but when button is clicked to enter, it opens a non-functioning app. (Edited since first posted trying many things, but core issue remains the same). Any ideas? Thank you.
You need to remove calling wall template from body tags.
So your wall.html will be:
<head>
<title>LKG Canvas</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="http://files.codepedia.info/uploads/iScripts/html2canvas.js"></script>
</head>
<body>
</body>
<template name="wall">
<!-- <h1>{{title}}</h1> -->
<div id="settings">
<div>
<button class='eraser' button id="btn btn-link"><span class="glyphicon glyphicon-erase"></span></button>
<button class='clear' button id="btn btn-link"><span class="glyphicon glyphicon-remove"></span></button>
...
</div>
<div id="settings">
<button class='thinnest'>1</button>
...
</div>
<div id="settings">
<button class='shade'>3%</button>
</div>
{{> canvas}}
</template>
<template name="canvas">
<div class="centerize">
<div id="canvas" style="background-color: #333; width: 1250px; height: 550px;"></div>
<br>
<input id="btn-Preview-Image" type="button" value="Preview"/>
<a id="btn-Convert-Html2Image" href="#">Download</a>
<div id="previewImage"></div>
</div>
</template>
How about this approach:
router.js
Router.route ( '/', {
name:'home',
layoutTemplate:'index',
});
Router.route('/wall', {
name:'wall',
layoutTemplate:'index',
});
home.html is as is, no changes:
<template name="home">
<div class="container">
<div class="jumbotron">
<h1>Heading</h1>
<p>Some text here.</p>
</div>
<div>
<div class="centerize">
<a class="btn btn-primary btn-lg" href="wall" role="button">Draw</a></div>
</div>
</div>
</template>
wall.html, removed the <body> stuff
<template name="wall">
<!-- <h1>{{title}}</h1> -->
<div id="settings">
<div>
<button class='eraser' button id="btn btn-link"><span class="glyphicon glyphicon-erase"></span></button>
<button class='clear' button id="btn btn-link"><span class="glyphicon glyphicon-remove"></span></button>
...
</div>
<div id="settings">
<button class='thinnest'>1</button>
...
</div>
<div id="settings">
<button class='shade'>3%</button>
</div>
{{> canvas}}
</template>
<template name="canvas">
<div class="centerize">
<div id="canvas" style="background-color: #333; width: 1250px; height: 550px;"></div>
<br>
<input id="btn-Preview-Image" type="button" value="Preview"/>
<a id="btn-Convert-Html2Image" href="#">Download</a>
<div id="previewImage"></div>
</div>
</template>
index.html
<template name="index">
{{> yield}}
</template>
Index.html basically encompasses the other routes that will render in the yield region.
I am having a bit of a problem with a form on a drop down in the foundation 5 framework.
Basically I am assigning an input field and button to a dropdown menu, which works fine.
But as I can't firstly see a Back button like I can on the first dropdown, I can't see any reasons why. When basic code is a replication.
After viewing the second dropdown and going back to the menu to view dropdown one the input field and button are visible...
Source code below:
CSS:
.has-form-small {
top: 0rem;
left: 0rem;
min-width: 15rem; }
#media only screen and (max-width: 40em) {
.has-form {
min-width: 10rem;
top: 0 rem; }
.has-form .button {
height: 3rem; } }
</style>
HTML:
Dropdown 1:
<section class='top-bar-section'>
<!-- Right Nav Section -->
<ul class='right'>
<li><a href='#'>Button</a></li>
<li class='has-dropdown'>
<a href='#'>Dropdown</a>
<ul class='dropdown'>
<li><a href='#'>link</a></li>
<li><a href='#'>link</a></li>
</ul>
</li>
</ul>
</section>
Dropdown 2:
<section class='top-bar-section'>
<!-- Right Nav Section-->
<strong class='show-for-small-only'>
<ul class='right'>
<li class='has-dropdown'>
<a href='#'>Dropdown2</a>
<ul class='dropdown'>
<li class='has-form-small'>
<div class='row collapse'>
<div class='large-9 small-9 columns'>
<input type='text' placeholder='Find Stuff'>
</div>
<div class='large-3 small-3 columns'>
<a href='#' class='alert button expand'>Search</a>
</div>
</div>
</li>
</ul>
</li>
</ul>
</strong>
</section>
Managed to fix in the end. Turns out a drop down menu option isn't needed.
Code as below:
CSS:
<style>
.has-form-small {
color: darkslategray;
position: absolute;
top: 0rem;
left: 0rem;
min-width: 26rem;
min-height: 2.7rem;}
#media only screen {
.has-form-small {
color: darkslategray;
min-width: 26rem;
min-height: 2.7rem;
top: 0rem; }
.has-form-small .button {
color: darkslategray;
width: 10rem;}}
</style>
HTML:
<nav class='top-bar' data-topbar role='navigation'>
<ul class='title-area'>
<li class='name'>
<h1><a href='#'>My Site</a></h1>
</li>
<strong class='hide-for-small-only'>
<li class='has-form'>
<div class='row collapse'>
<div class='large-9 small-9 columns'>
<input type='text' placeholder='Find Stuff'>
</div>
<div class='large-3 small-3 columns'>
<a href='#' class='alert button expand'>Search</a>
</div>
</div>
</li>
</strong>
<!-- Remove the class 'menu-icon' to get rid of menu icon. Take out 'Menu' to just have icon alone -->
<li class='toggle-topbar menu-icon'><a href='#'><span>Menu</span></a></li>
</ul>
<section class='top-bar-section'>
<!-- Right Nav Section -->
<ul class='right'>
<li><a> </a></li>
<li>
<strong class='show-for-small-only'>
<li class='has-form-small'>
<div class='large-12 small-9 columns'>
<input type='text' placeholder='Find Stuff'>
</div>
<div class='large-3 small-3 columns'>
<a href='#' class='alert button expand'>Search</a>
</div>
</li>
</strong>
</li>
</ul>
<ul class='right'>
<li><a href='#'>Button</a></li>
<li class='has-dropdown'>
<a href='#'>Dropdown</a>
<ul class='dropdown'>
<li><a href='#'>link</a></li>
<li><a href='#'>link</a></li>
</ul>
</li>
</ul>
<!-- Left Nav Section -->
<ul class='left'>
</ul>
</section>
</nav>
There may be better ways to do this (e.g. remove blank row with "&nspb") but I was having issues with background colours, and this is supposed to only be a demo site.