///
/// @returns {Mixed} The value for the key after `$key`, if `$key` was found. If `$key` was not found, or `$key` was the last value in the map, returns `null`.
@function -zf-map-next($map, $key) {
- // Store the values of the map as a list, so we can access them with nth
+
+ // Store the keys of the map as a list
$values: map-keys($map);
- // Get the index of the key within the map and add 1 to it for the next breakpoint in the map
- $i: index($values, $key) + 1;
+ $i: 0;
+
+ // If the Key Exists, Get the index of the key within the map and add 1 to it for the next breakpoint in the map
+ @if (map-has-key($map, $key)) {
+ $i: index($values, $key) + 1;
+ }
// If the key doesn't exist, or it's the last key in the map, return null
- @if $i > length($map) {
+ @if ($i > length($map) or $i == 0) {
@return null;
}
// Otherwise, return the value
@else {
@return map-get($map, nth($values, $i));
-
}
+
}
/// Get a value for a breakpoint from a responsive config map. If the config map has the key `$value`, the exact breakpoint value is returned. If the config map does *not* have the breakpoint, the value matching the next lowest breakpoint in the config map is returned.